# Disable & required

**URL:** <https://jsonforms.discourse.group/t/disable-required/2483>\
**Category:** General\
**Created:** [December 3, 2024, 11:31am UTC](https://jsonforms.discourse.group/t/disable-required/2483 "2024-12-03T11:31:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![clysss](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/clysss/32/996_2.png) [@clysss](https://jsonforms.discourse.group/u/clysss)\
**Post date:** [December 3, 2024, 11:31am UTC](https://jsonforms.discourse.group/t/disable-required/2483/1 "2024-12-03T11:31:40Z")

</div>

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!

---

<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:** [December 3, 2024, 11:40am UTC](https://jsonforms.discourse.group/t/disable-required/2483/2 "2024-12-03T11:40:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![clysss](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/clysss/32/996_2.png) [@clysss](https://jsonforms.discourse.group/u/clysss)\
**Post date:** [December 3, 2024, 11:44am UTC](https://jsonforms.discourse.group/t/disable-required/2483/3 "2024-12-03T11:44:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![clysss](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/clysss/32/996_2.png) [@clysss](https://jsonforms.discourse.group/u/clysss)\
**Post date:** [December 3, 2024, 12:18pm UTC](https://jsonforms.discourse.group/t/disable-required/2483/4 "2024-12-03T12:18:54Z")

</div>

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 ?)

---

<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:** [December 5, 2024, 7:21am UTC](https://jsonforms.discourse.group/t/disable-required/2483/5 "2024-12-05T07:21:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![clysss](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/clysss/32/996_2.png) [@clysss](https://jsonforms.discourse.group/u/clysss)\
**Post date:** [December 5, 2024, 10:23am UTC](https://jsonforms.discourse.group/t/disable-required/2483/6 "2024-12-05T10:23:17Z")

</div>

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

---

<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:** [December 5, 2024, 11:18am UTC](https://jsonforms.discourse.group/t/disable-required/2483/7 "2024-12-05T11:18:36Z")

</div>

See this [documentation of AJV](https://ajv.js.org/guide/user-keywords.html)

---

<div class="post-metadata">

**Author:** ![clysss](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/clysss/32/996_2.png) [@clysss](https://jsonforms.discourse.group/u/clysss)\
**Post date:** [December 5, 2024, 11:33am UTC](https://jsonforms.discourse.group/t/disable-required/2483/8 "2024-12-05T11:33:31Z")

</div>

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