Type/Format validation error with custom date control


I created a custom date picker control with Material-UI-pickers and DateFns. My simple field looks like:

          format: date
          type: string

The component works and saves but the built in jsonforms validator gives me an error saying type must be string. When I convert the date in handlechange() to string, I get the error that the value must match the format “date”. Link below for the 2 errors in redux. You can see that it looks like a string already… but it fails validation. I’m not sure where to go from here. I would turn off validation from one field if that is possible. Thanks for any help!

[original thread by Ricardo Guntur]

Hi @ricardo-guntur, this is an interesting issue. The first case is obvious: as the property is modeled as string, it needs to be a string to pass validation. So your approach to convert the date to string looks correct to me.

I think the reason that Ajv complains about the string version of your date is that it does not correspond to the format specified in your JSON schema. In the JSON schema the string format is specified as date, while the actual value uses a date-time format. The three time-related formats are date, time and date-time. So you should either convert your string to only represent a date or change the JSON schema format to date-time.

Regarding skipping validation: The simplest solution is to just remove the format property from your JSON schema. If you definitely have to modify validation instead you could wrap the Ajv instance you give to JSON Forms and return a validator which filters the error for this property. However in general I would recommend avoid doing that and rather fix the issue properly, in your case as described above.

[Ricardo Guntur]

Hi @sdirix!

Thanks for the advice, it really helped. I went with removing the format property. I was referencing the date format with the tester isDateFormat but I can work around that.

In this case I only need to convert the date to a string and there are no errors. And the component still reads the value properly from redux.