Disable fields based on empty field

Hello guys, I’m implementing a form using the library, and I’m having problems adding fields and disabling them if another field is empty. Is this functionality allowed? I have tried with the DISABLE rule and a const with null in the schema but it is not working. Is it okay to say that the initial field value is null?

Thank you in advance!

Hi @IvanAprea,

By default initial field values are undefined. The issue you are likely running into is that for JSON Schema undefined has no meaning. Therefore any rule will succeed for undefined values.

If that is the issue you are running into then you have two ways of solving it:

  • Modify your schema in the rule to point to the parent of the value instead and then use required to let the rule fail in case the property does not exist. That’s the JSON Schema way to handle undefined values
  • Alternatively you can use failWhenUndefined to let a rule fail when the value it refers to is undefined. This property is a sibling to the schema in the rule.