We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
title
ui:title
validator-ajv8
5.22.2+
Validation errors with localizer do not show title or ui:title.
const ajv8 = require("@rjsf/validator-ajv8"); const localizer = require("ajv-i18n"); const schema = { type: "object", required: ["a"], properties: { a: { type: "string", title: "A", }, }, }; const validator = ajv8.customizeValidator({}, localizer.en); const result = validator.validateFormData({}, schema); console.log(result.errors[0].message);
This result in must have required property a.
must have required property a
This only happens with localizer and is a side effect of #4349 and compatibility issue with ajv-i18n.
must have required property 'A' is expected. It should be better to always show title or ui:title instead of showing property.
must have required property 'A'
Possible workaround might be following but I am not too sure this is a right approach or not.
diff --git a/packages/validator-ajv8/src/validator.ts b/packages/validator-ajv8/src/validator.ts index 60dce8db..fb5bea0f 100644 --- a/packages/validator-ajv8/src/validator.ts +++ b/packages/validator-ajv8/src/validator.ts @@ -90,7 +90,18 @@ export default class AJV8Validator<T = any, S extends StrictRJSFSchema = RJSFSch let errors; if (compiledValidator) { if (typeof this.localizer === 'function') { + (compiledValidator.errors ?? []).forEach((error) => { + if (error.params?.missingProperty) { + error.params.missingProperty = `'${error.params.missingProperty}'`; + } + }); this.localizer(compiledValidator.errors); + (compiledValidator.errors ?? []).forEach((error) => { + if (error.params?.missingProperty) { + error.params.missingProperty = error.params.missingProperty.slice(1, -1); + } + }); } errors = compiledValidator.errors || undefined;
Please see above.
- OS: Ubuntu 22.04 - Node: 20.15.1 - npm: 10.7.0
No response
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Prerequisites
What theme are you using?
validator-ajv8
Version
5.22.2+
Current Behavior
Validation errors with localizer do not show
title
orui:title
.This result in
must have required property a
.This only happens with localizer and is a side effect of #4349 and compatibility issue with ajv-i18n.
Expected Behavior
must have required property 'A'
is expected. It should be better to always showtitle
orui:title
instead of showing property.Possible workaround might be following but I am not too sure this is a right approach or not.
Steps To Reproduce
Please see above.
Environment
Anything else?
No response
The text was updated successfully, but these errors were encountered: