[zwjohn]
@sdirix once again, thanks for the feedback and information provided, I will try to do that. Also, I am trying to implement custom error message, so I installed ajv-errors package hoping providing some custom error messages. However, the custom error message may not have a dataPath if it’s top level, and therefore the error messages don’t show anymore once custom message is implemented. According to the author of AJV, this is expected as some required field can be on top level, and no dataPath needed. Please refer to this link about the discussion Missing dataPath attribute for required field · Issue #1133 · ajv-validator/ajv · GitHub . It seems that JsonForms wouldn’t render error message without dataPath, that’s why I am not getting error messages after implemented custom AJV with ajv-errors. Can you please take a look?
export const createAjv = (options) => {
const ajv = new AJV({
schemaId: ‘auto’,
allErrors: true,
jsonPointers: true,
messages:true,
…options
});
return ajv;
};
export const myAjv = new AJError(createAjv());
This is my testing schema
const schema = {
“type”: “object”,
“properties”: {
“name”: {
“type”: “string”,
“minLength”: 3,
“maxLength”:4,
“description”: “Please enter your name”,
},
“vegetarian”: {
“type”: “boolean”
},
“birthDate”: {
“type”: “string”,
“format”: “date”
},
"nationality": {
"type": "string",
"enum": [
"DE",
"IT",
"JP",
"US",
"RU",
"Other"
]
},
"personalData": {
"type": "object",
"properties": {
"age": {
"type": "integer",
"description": "Please enter your age."
},
"height": {
"type": "number"
},
"drivingSkill": {
"type": "number",
"maximum": 10,
"minimum": 1,
}
},
"required": [
"age",
"height"
],
"errorMessage": {
"required": {
"age": "Age Missing",
"height": "Height Missing ",
}
}
},
"occupation": {
"type": "string"
},
"postalCode": {
"type": "string",
"maxLength": 5
}
},
"required": [
"occupation",
"nationality",
"name"
],
"additionalProperties ": true,
"errorMessage": {
"type": 'should be an object',
"required": {
"name": "Name Missing",
"nationality": "Nationality Missing ",
"occupation": "Occupation Missing ",
}
}
};