rjsf-team / react-jsonschema-form

A React component for building Web forms from JSON Schema.
https://rjsf-team.github.io/react-jsonschema-form/
Apache License 2.0
14.18k stars 2.18k forks source link

validator and customValidate both are validating fields #4206

Open Vineet060 opened 4 months ago

Vineet060 commented 4 months ago

Prerequisites

What theme are you using?

antd

Version

5.x

Current Behavior

I'm applying validation with customValidate but in that case default validator props also applying validation and validator is required props.

So cause of this i'm seeing two validation message one is coming from validator and second is coming from custom validator.

image

Expected Behavior

Default validator should not work if i'm using custom validation.

Steps To Reproduce

No response

Environment

- OS:
- Node:
- npm:

Anything else?

No response

nickgros commented 3 months ago

This is not a bug, most users want to use customValidate to enhance the validator rather than replace it.

You could stub transformErrors to remove all of the errors provided by the validator. It looks like it runs before customValidate, so just return an empty array of errors in transformErrors and the validator errors should be removed.

See docs here.

For your case, I would just make transformErrors look something like this:

function transformErrors(errors, uiSchema) {
  // Remove all errors reported by the validator
  return []
}