Custom error messages

Hi,

we have integrated jsonforms with react app, can you please share the examples how to integrated ajv for custom error messages.

thanks

[original thread by kirannaikRNR]

Hi. You can use ajv-errors for that. Note that we currently use Ajv v6, therefore you also need to use ajv-errors v1. You can use the createAjv function exported from @jsonforms/core to create your Ajv instance, customize it with ajv-errors and then pass it as a prop to JsonForms.

[kirannaikRNR]

thanks for the quick response
I have installed ajv-errors v1

first I have a added a property called errorMessage in my schema
ie: errorMessage : “test message”
and then const ajv = createAjv();
const validate = ajv.compile(schema);
and finally passing ajv obj as props to jsonforms

im still seeing the default messages

are my steps are correct please help me.
thanks

Update: We updated to AJV v8 starting with version v3.0.0-alpha.2. Therefore if you want to use ajv-errors you will also need to update it now.

Also we reworked the internationalization support in JSON Forms in general. So this could be used instead of ajv-errors. There are no docs yet. Until they are available there is some information in this issue. A working example can be found in the example app of the vuetify renderers.

And as a follow-up information:
If you run into issues similar like this

You have to install ajv additionally
npm install ajv

As this post still receives views: The i18n support is now fully there for JSON Forms and provides a very easy mechanism for customizing error messages. See the docs here.