react-jsonschema-form icon indicating copy to clipboard operation
react-jsonschema-form copied to clipboard

Single field-level live validation

Open snailracer opened this issue 6 years ago • 5 comments

Prerequisites

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?

snailracer avatar Oct 18 '19 06:10 snailracer

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?

epicfaace avatar Oct 22 '19 23:10 epicfaace

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 avatar Nov 24 '19 09:11 jmaister

@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?

epicfaace avatar Dec 09 '19 05:12 epicfaace

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!

KKS1 avatar Jan 10 '20 21:01 KKS1

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.

jacqueswho avatar Jul 29 '22 15:07 jacqueswho