Skip to content

Commit

Permalink
FIO-8450: Fix custom error message for unique validation
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekotikov committed Jun 19, 2024
1 parent c859404 commit d991bbd
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/process/validation/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export function isObject(obj: any): obj is Object {
return typeof obj != null && (typeof obj === 'object' || typeof obj === 'function');
}

const getErrorMessage = ({ errorKeyOrMessage, context }: FieldError) =>
context.component?.errors?.[errorKeyOrMessage] || errorKeyOrMessage;

/**
* Interpolates @formio/core errors so that they are compatible with the renderer
* @param {FieldError[]} errors
Expand All @@ -60,7 +63,7 @@ export const interpolateErrors = (errors: FieldError[], lang: string = 'en') =>
return errors.map((error) => {
const { errorKeyOrMessage, context } = error;
const i18n = VALIDATION_ERRORS[lang] || {};
const toInterpolate = i18n[errorKeyOrMessage] ? i18n[errorKeyOrMessage] : errorKeyOrMessage;
const toInterpolate = i18n[errorKeyOrMessage] ? i18n[errorKeyOrMessage] : getErrorMessage(error);
const paths: any = [];
context.path.split('.').forEach((part) => {
const match = part.match(/\[([0-9]+)\]$/);
Expand Down

0 comments on commit d991bbd

Please sign in to comment.