I’m using customs ajv-errors.
after update from 3.6 to 3.7 the error messages are no more customs…
my main call looks like ;
<JsonForms
//i18n={{translate: translator}}
schema={schemasQuery.data.schema as JsonSchema}
uischema={schemasQuery.data.uiSchema}
data={isEmpty(jsonFormData) ? schemasQuery.data.data : jsonFormData}
renderers={renderers}
cells={materialCells}
ajv={xcreateAjv()}
validationMode="ValidateAndShow"
onChange={({ data, errors }) => {
setJsonFormData(data);
setJsonFormErrors(errors);
}}
and my ajv.ts containng the xcreateajv is :
import ajvErrors from ‘ajv-errors’;
import { createAjv } from ‘@jsonforms/core’;
const formats = {
email: {
type: 'string',
validate: (data: string) => /^\[^\\s@\]+@\[^\\s@\]+\\.\[^\\s@\]+$/.test(data),
},
phone: {
type: 'string',
validate: (data: string) => /^\\+\[0-9\]+$/.test(data),
},
url: {
type: 'string',
validate: (data: string) => /^https:\\/\\/.+/.test(data),
},
linkedin: {
type: 'string',
validate: (data: string) => /^https:\\/\\/(www\\.)?linkedin\\.com\\/(in|company)\\/\[\\w-\]+\\/?$/.test(data),
},
// reconnaître le format SVG et arrêter les messages d’erreur //////////////////////DO NOT WORK as not in schema (in schemaui)
‘upload-logo’: {
validate: (str: string) => {
return typeof str === 'string';
},
errorMessageKey: 'validation_svgInvalid',
errorMessage: "URL invalid - must begin with https://",
}
};
export const xcreateAjv = () => {
const myAjv=createAjv({
allErrors: true,
verbose: true,
$data: true,
strict: false,
messages: true
});
ajvErrors(myAjv);
// Define the totalPercentage keyword
myAjv.addKeyword({
keyword: 'totalPercentage',
type: 'array',
validate: function (schema: any, data: any) {
if (!Array.isArray(data)) return false; // Ensure data is an array
const total = data.reduce((sum: number, entry: any) => sum + (entry.percent || 0), 0);
return total === 100; // Check if total equals 100
},
errors: false, // Set to true if you want to use custom error messages
});
Object.entries(formats).forEach((\[name, format\]) => {
myAjv.addFormat(name, format.validate);
});
return myAjv;
};
I tried with or without updating ajv package, both failed
which version of ajv should we use?
how should we write with new jsonforms?
Thx a lot!