Skip to content

Commit 11cbb3b

Browse files
Move custom 'required' errorMessage one level up in the schema's hierarchy to enable ajv-errors to work correctly
1 parent a9b9f60 commit 11cbb3b

File tree

1 file changed

+13
-0
lines changed
  • src/vfjs-global-mixin/methods/vfjs-validation

1 file changed

+13
-0
lines changed

src/vfjs-global-mixin/methods/vfjs-validation/getters.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,19 @@ const vfjsValidationGetters = {
106106

107107
if (isRequired) {
108108
set(schema, required, [path]);
109+
110+
// IF ajv-errors plugin is present (errorMessage keyword is added)
111+
// AND fieldSchema has a custom errorMessage definition:
112+
// THEN add that errorMessage one level up in the schema's hierarchy
113+
// (right next to where the required fields are defined)
114+
// so that ajv can handle this properly with the ajv-errors plugin
115+
if (this.ajv.RULES.keywords.errorMessage && fieldSchema.errorMessage) {
116+
const errorMessagePath = previousPaths.length > 0
117+
? `${previousProperties}.errorMessage`
118+
: 'errorMessage';
119+
120+
set(schema, errorMessagePath, fieldSchema.errorMessage);
121+
}
109122
}
110123
} else {
111124
set(schema, properties, {});

0 commit comments

Comments
 (0)