Validation of an optional object property that contains an enum

As I’m getting familiar with jsonforms I’ve been looking into how it handles the case where the schema has an optional property that’s an object, that in turn has a required property. Another json schema forms package I was looking at seems to always require that property to be set, despite the fact that the object itself is optional, which is a big problem with the schemas I’m working with.

It looks like jsonforms validation generally does the right thing if no properties are filled in on that object. It seems to treat it as if the optional object property is not set at all, so validation doesn’t fail on its required property. However, if one of the properties on that optional object is an enum, I can’t clear it so it has no value. The select lists only the available enum values. Therefore, the optional object isn’t empty and validation fails on the required property.

It seems to me that an enum select should include a “None” option so you can clear the value for the property. Should I file an issue on this or am I missing something?

Hi @dieseldjango,

which renderer set are you using in which version? I think only the Angular renderers don’t provide an empty option for now.

Note that there is quite some discussion around enum controls and whether they should even support setting a “None” option and if yes, under which conditions, see for example here.

I would like to suggest that you just implement the behavior you would like to see via a custom renderer. If you make it generic and configurable you could think about a contribution to JSON Forms to make it available to the community at large.

Regarding validation: We use AJV to validate the data according to the JSON Schema and then map the errors to the form elements where they make sense. We don’t have any custom validation logic within JSON Forms.

Hi @sdirix, I’m using the material ui renderer set. What I see is that I can validate ok if the empty optional object has no enum, but not if it does. The drop down to select an enum value has no “None” option.

I’ll look into a custom renderer.

Hi @dieseldjango, I think the styling is a bit off. The none option has no label and is pretty slim at the top. This should be fixed of course.