Disable & required

hello,
I’ve a very large number of rules who disable some questions
most of them are Required, but of course, not when disable
I tried to use if then else to modify Required but it’s not usable as I’ve to write 2 times the rules and it’s far too much complicated
I need the required to be able to block the form if fields are not completed
Option1 : Is it possible to modify the general comportment of Required to say that I the field is disabled or hidden, Required must not be used ?
Option 2 : all my displays use custom controls : is there a way to modify the property Required to false dynamicaly inside (i mean to modify in the schema, not the display…) ?
Thx!

Hi @clysss,

Rendering and Validation are two completely separate functionalities in JSON Forms. Therefore you can’t influence the validation results via the UI Schema.

Of course, what you can do is to use custom renderers to behave differently than the JSON Forms’ off-the-shelf renderers. For example in case a control is disabled (i.e. enabled === false), then you could just not display the errors.

yes but dont showing error will not help me to validate the form :wink:
and as I don’t see how to create my own error inside my component (back to a previous issue /post here :wink:

could I use a custom validator for AJV to check if data is not empty ? (not seems to be called when data is empty – a way to force the call when custom cntrl is loaded ?)

AJV does not call any validators on undefined properties. However you could add a custom keyword on objects and then perform the validation on the object containing the properties. In difference to the AJV required errors, you could then point to the non-existing properties.

Seems very interesting :slight_smile: When you talk about custom keyword, could you give me an example of ? Is it to add it on schema/ui?

See this documentation of AJV

Oh you mean a custom ajv keyword ? I already tried that but when data is undefined, the ajv is never called