Skip to main content

Validation

Whenever you change data in the forms generated by JSON Forms, it will be validated in the background in order to display any messages that violate the JSON schema.

Validation is handled by AJV and can be customized by passing a custom AJV instance as a prop to the JsonForms standalone component.

If you do not customize the validator, a default instance will be created for you. That default instance is configured as follows:

const ajv = new AJV({
schemaId: 'auto',
allErrors: true,
jsonPointers: true,
errorDataPath: 'property',
verbose: true,
...options,
});
ajv.addFormat('time', '^([0-1][0-9]|2[0-3]):[0-5][0-9]$');
ajv.addMetaSchema(Draft4);

You can either create your own instance or you can use the createAjv function provided by JSON Forms that allows overriding the default options by passing in additional options.

For customizing or localizing AJV error messages we recommend ajv-errors.

ValidationMode#

There are three different validation modes:

  • ValidateAndShow: Validates, emits and shows errors (which is the default)
  • ValidateAndHide: Validates and emits errors, but does not show them
  • NoValidation: Does not validate at all

You can set the validation mode in each JSON Form's root component. For example in React it could look like this:

<JsonForms
schema={schema}
uischema={uischema}
data={data}
renderers={materialRenderers}
cells={materialCells}
validationMode={currentValidationMode}
/>

Here you can see the different modes in action



Current mode: ValidateAndShow
Emitted errors: