Is it possible to make a Rule that only shows a field if it's required?

I have a requirement for a form that’s reused in various places that has a field we don’t want to display unless it’s set as required. Is it possible to do this with a Rule in a UI schema?

I’ve tried {"scope": "<scope of parent element>", "schema": {"required": ["<child field>"]}} but that shows the field regardless of whether it’s required or not.

Hi @mb123,

The schema-condition you used indicates that the rule will apply when the field exists in the data.

I don’t fully understand the requirement. Reusing a form means to me that the schema and uischema are reused. However in your requirement the schema will be different: sometimes a property is set to required, sometimes not.

So I would like to suggest maintaining not only two different schema, but also two different uischema. One of the pairs has the schema with the field set to required and the uischema including a Control for it, the other one has the schema with the field not set to required and the uischema not including the Control.

Alternatively you could implement a custom renderer which hides/shows a field depending on whether it’s required. This way you would not need to maintain your own Ui Schemas.