TLDR: I need to customize the default error messages provided by JSON form. Eg if field is required
then JSON form give error like is a required property
, I want it to return error message text like Invalid input....
I've created a JSON form with schema something like
{
type: 'object',
properties: {
name: {
type: 'string',
minLength: 3,
},
},
required: [
'name',
],
errorMessage: {
required: 'INVALID INPUT. This is a required field',
},
};
Now I've used this schema and a UI schema to create a JSON form
const ajv = createAjv();
require('ajv-keywords')(ajv);
require('ajv-errors')(ajv);
<JsonForms
schema={schema}
uischema={uischema}
data={data}
renderers={CustomRenderers}
cells={vanillaCells}
onChange={onChange}
ajv={ajv}
/>
The above JSON form renders a UI form and when field is empty is gives standard error message like is a required property
, now here i need to override with my own custom message, for that purpose https://github.com/ajv-validator/ajv-errors found to be useful and added property errorMessage
in my schema, with required
key having my custom message, also i added require('ajv-errors')(ajv);
as it is needed but still im getting the default error message and not the one that i overwrite with in errorMessage
.
Am i missing something here? Or can i have some other way to override the default message. Also along with required
I'll have lot validations like minLength
, maxLength
etc whose default message i might have to override.
Also I'm expecting a lot other properties in schema, so adding errorMessage
in every properties might not be very efficient, but if that is the only solution I've to go with it:)