Skip to content

Commit

Permalink
Merge pull request #219 from formio/fix/FIO-9668_custom_error_message…
Browse files Browse the repository at this point in the history
…s_are_not_highlighted

FIO-9668: Fix custom error messages are not highlighted
  • Loading branch information
brendanbond authored Feb 3, 2025
2 parents 136fe63 + 5da6bb0 commit c3d6b9c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/error/FieldError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ export class FieldError {
level = 'error',
} = context;
this.ruleName = ruleName;
this.level = level;
if (context.component.validate?.customMessage) {
this.errorKeyOrMessage = context.component.validate.customMessage;
this.context = { ...context, hasLabel: false, field, level };
} else {
this.errorKeyOrMessage = errorKeyOrMessage;
this.context = { ...context, hasLabel, field };
this.level = level;
}
}
}
Expand Down
42 changes: 42 additions & 0 deletions src/process/__tests__/process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5875,5 +5875,47 @@ describe('Process Tests', function () {
processSync(context);
expect(context.data).to.deep.equal({ selector: false, container: { textField: 'test' } });
});

it("Should save 'level' field when custom error message is defined to correctly add error classes into app template ", async function () {
const components = [
{
label: "Text Field",
applyMaskOn: "change",
tableView: true,
validate: {
required: true,
customMessage: "mikhail"
},
validateWhenHidden: false,
key: "textField",
type: "textfield",
input: true
},
{
label: "Submit",
showValidations: false,
tableView: false,
key: "submit",
type: "button",
input: true,
saveOnEnter: false
}
];
const submission = {
data: {
textField: "",
submit: true
}
}
const context = {
submission,
data: submission.data,
components,
processors: ProcessTargets.evaluator,
scope: {} as { errors: Record<string,unknown>[] }
};
processSync(context);
expect(context.scope.errors[0].level).to.equal("error");
});
});
});

0 comments on commit c3d6b9c

Please sign in to comment.