diff --git a/src/process/validation/util.ts b/src/process/validation/util.ts index 0ac06c42..ab5637dc 100644 --- a/src/process/validation/util.ts +++ b/src/process/validation/util.ts @@ -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 @@ -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]+)\]$/);