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

**URL:** <https://jsonforms.discourse.group/t/is-it-possible-to-make-a-rule-that-only-shows-a-field-if-its-required/2353>\
**Category:** General\
**Created:** [September 19, 2024, 11:59am UTC](https://jsonforms.discourse.group/t/is-it-possible-to-make-a-rule-that-only-shows-a-field-if-its-required/2353 "2024-09-19T11:59:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mb123](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@mb123](https://jsonforms.discourse.group/u/mb123)\
**Post date:** [September 19, 2024, 11:59am UTC](https://jsonforms.discourse.group/t/is-it-possible-to-make-a-rule-that-only-shows-a-field-if-its-required/2353/1 "2024-09-19T11:59:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sdirix](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/sdirix/32/1073_2.png) [@sdirix](https://jsonforms.discourse.group/u/sdirix)\
**Post date:** [September 19, 2024, 1:04pm UTC](https://jsonforms.discourse.group/t/is-it-possible-to-make-a-rule-that-only-shows-a-field-if-its-required/2353/2 "2024-09-19T13:04:21Z")

</div>

Hi @mb123,

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

> [@mb123](#):
>
> form that’s reused in various places that has a field we don’t want to display unless it’s set as required.

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.
