-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Closed
Labels
bugneeds triageInitial label given, to be assigned correct labels and assignedInitial label given, to be assigned correct labels and assigned
Description
Prerequisites
- I have searched the existing issues
- I understand that providing a SSCCE example is tremendously useful to the maintainers.
- I have read the documentation
- Ideally, I'm providing a sample JSFiddle, Codesandbox.io or preferably a shared playground link demonstrating the issue.
What theme are you using?
validator-ajv8
Version
5.22.2+
Current Behavior
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
.
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 show title
or ui:title
instead of showing property.
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;
Steps To Reproduce
Please see above.
Environment
- OS: Ubuntu 22.04
- Node: 20.15.1
- npm: 10.7.0
Anything else?
No response
TheOneTheOnlyJJ
Metadata
Metadata
Assignees
Labels
bugneeds triageInitial label given, to be assigned correct labels and assignedInitial label given, to be assigned correct labels and assigned