react-jsonschema-form
react-jsonschema-form copied to clipboard
Single field-level live validation
Prerequisites
- [x] I have read the documentation;
Description
We're currently looking at restricting live validation to only apply to the field that has been changed, rather than at the entire form level which it is doing. From looking at the documentation and the code, we don't believe this is something that is currently supported? Is our understanding here correct?
We have looked at using custom validator but it still dosen't prevent the default behaviour (i.e. supressing validation of all required fields at once.)
This old issue that seems to call for this behaviour (albeit calling for onBlur rather than onChange) but was closed
https://github.com/rjsf-team/react-jsonschema-form/issues/617
Expected behavior
Live validation only triggers for fields that have been interacted with
Actual behavior
Live validation fires for all form fields that are marked as required in our schema
Version
1.8.0
Is this something that you have on your current product roadmap, or would consider adding in the near future?
Yes, this currently is not supported. We would consider adding it if we could come up with a good intuitive API for doing so. Do you have any ideas?
I came up with the same issue.
For the new design, I would add a different "onChange" property that accepts the same parameters. At the moment "onChange" receives all the schema/model, but I can't know which field just changed like "onBlur".
Example of usage:
onChangeField={(model, propertyChangedId, value) => {
if (propertyChangedId === "...client_id...") {
model.address = clientService.getClient(value);
}
}}
@jmaister how would that solution solve the issue with single field-level live validation?
Also, how would that solution work if, say, someone is selecting something that triggers a dependency and then multiple fields change at the same time?
Added a solution for blur based selective validation on https://github.com/rjsf-team/react-jsonschema-form/issues/617#issuecomment-573215262.
Hope it helps, anyone looking for the same!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please leave a comment if this is still an issue for you. Thank you.