RXNT/react-jsonschema-form-conditionals

Form sends onChange before conditional re-validation applied

mrclay opened this issue · 3 comments

We have lots of required conditionally displayed questions and the Form's onChange is firing too early, sending us the set of errors before the revalidation of the new schema has been completed.

Our current workaround is to have several of our widgets (ones which affect others) call onChange a second time after a short delay. After the delay the Form internally has the correct set of errors considering all rules.

@mrclay Can you provide an example of a form and change that is happening.
Thanks in advance.

Faced the same issue. Here is my example:

schema: {
	"type": "object",
	"required": [
	  "field2"
	],
	"properties": {
	  "checkbox": {
	    "type": "boolean",
	    "default": false
	  },
	  "field1": {
	    "type": "string"
	  },
	  "field2": {
	    "type": "string"
	  }
	}
}
rules: [{
	"conditions": {
	 "checkbox": {
	    "is": true
	 }
	},
	"event": [
	  {
	    "type": "remove",
	    "params": {
	      "field": [
	        "field2"
	      ]
	    }
	  },
	  {
	    "type": "require",
	    "params": {
	      "field": [
	        "field1"
	      ]
	    }
	  }
	]
}]

When you submitting form you will get required field2 in errors
After applying checkbox onChange event still handling error in field2 which is not exist on form.
The only way to overrite errors is to submit the form but in real app there are cases that prevent me from using it.

I'm sorry I've not been able to provide an example form. They're all large and use many custom widgets/fields, and to be fair it's quite possible our problems lie there.