From 01ba93e9d71cb5d72affe449cdf184e3dfccf221 Mon Sep 17 00:00:00 2001 From: mikekotikov Date: Wed, 19 Jun 2024 13:50:08 +0200 Subject: [PATCH] FIO-8450: Fix custom error message for unique validation --- src/process/validation/util.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/process/validation/util.ts b/src/process/validation/util.ts index 0ac06c42..78e665e4 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 getCustomErrorMessage = ({ errorKeyOrMessage, context }: FieldError): string => + context.component?.errors?.[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 = getCustomErrorMessage(error) || i18n[errorKeyOrMessage] || errorKeyOrMessage; const paths: any = []; context.path.split('.').forEach((part) => { const match = part.match(/\[([0-9]+)\]$/);