Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIO-8450: Fix custom error message for unique validation #106

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 getCustomErrorMessage = ({ errorKeyOrMessage, context }: FieldError): string =>
mikekotikov marked this conversation as resolved.
Show resolved Hide resolved
context.component?.errors?.[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 = getCustomErrorMessage(error) || i18n[errorKeyOrMessage] || errorKeyOrMessage;
const paths: any = [];
context.path.split('.').forEach((part) => {
const match = part.match(/\[([0-9]+)\]$/);
Expand Down
Loading