Hello, we discovered long ago that if we set the fields to be mandatory through allOf, then the asterisk disappears and the field becomes “required: false”.
For the sake of demonstration, I modified the sandbox from the previous thread, and find that “Field 3-3” has an error about being required, but no asterisk, as we have a common problem with both our custom renderers and “vanilla renderers”, I guess that the bug/feature is happening in the core.
Thanks in advance for your reply
Hi @CodeXiD,
Sadly, this is expected. For JSON Forms to support conditional “required” we would need to fully validate the data according to the JSON Schema ourselves, only then would we know when the "required’ annotation is applied to the corresponding property. The only way I ever see this feature being implemented is if that kind of functionality were exposed in AJV.
Sadly, that is, at the moment there is no possibility or example of how to get around this limitation?
The use cases for a single user are typically constrained, for example let’s say your conditional required are always of the form of allOf > some nested objects, or a simple if condition referring to an object on sibling level.
You can use custom renderers which are able to check for the use cases which occur in your actual schema. Because you’re not really changing the actual rendering behavior but are just interested in the required prop you can essentially reuse all off-the-shelf renderers of JSON Forms and just add an additional binding which checks your additional required use cases. This is the “clean” solution.
If you’re more interested in the “look” and don’t want to touch renderer code then you could use a hacky workaround via the i18n mechanism to return the label with a * in case the property is dynamically required or set the corresponding * label via the UI Schema.
I understand correctly, you mean that a clean solution involves ajv revalidation in custom renderers when data changes?