Set required using custom renderer

We are trying to implement custom solution for required field, as we want field level required attribute. so wanted to know how to set this.control.required in custom renderer

Hi @rohan.thakare,

I’m not sure whether I understand what you want to accomplish. If a property is required in JSON Schema the required prop will be set by JSON Forms. Then you can handle the prop in whatever way you like.

So we have written custom renderers, then in schema we are passing one custom attribute, eg
Preformatted text
“text-field”: {
“is-required”: true
}

then we want to utilise this “is-required” attribute to set this.control.required = true;
but field is not getting marked as required

Hi @rohan.thakare,

Is there a specific reason that you don’t use JSON Schema’s required? Using that instead you would get required automatically set to true.

If you want to stick with the custom is-required attribute, then I would like to suggest to simply check that instead. In your renderer you get the schema prop injected, containing the sub schema of your property. So to check whether is-required is set you can simply inspect props.schema.is-required.

Thanks Stefan,

Currently we are using JSON Schema’s required only, but there are some scenarios where we want required on one field which is inside an array, based on other field which is present outside array in some nested object.

So i am able to get is-required property in renderer, but what are not able to achieve is based on this is-required property we are not able to mark field as required

Not sure if youre hoping to put dependent required fields like when the value of Any select field name is A then gender field should become required you can achieve this using if-else validaiton