Skip to content

Commit 218a80d

Browse files
committed
fix remap errors that are not filtered out, fix filteredChildErrors to support filterErrorKeywordsBeforeTouch
1 parent 6c50eeb commit 218a80d

1 file changed

Lines changed: 47 additions & 12 deletions

File tree

packages/vue-vuetify/src/util/composition.ts

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ import {
1010
defaultJsonFormsI18nState,
1111
getArrayTranslations,
1212
getCombinatorTranslations,
13+
getCombinedErrorMessage,
1314
getControlPath,
15+
getErrorTranslator,
1416
getFirstPrimitiveProp,
17+
getTranslator,
1518
isDescriptionHidden,
1619
type ControlElement,
1720
type DispatchPropsOfControl,
@@ -132,6 +135,7 @@ export const useVuetifyLabel = <
132135
*/
133136
export const useVuetifyControl = <
134137
T extends {
138+
schema: JsonSchema;
135139
uischema: ControlElement;
136140
path: string;
137141
config: any;
@@ -198,13 +202,26 @@ export const useVuetifyControl = <
198202
(error) => input.control.value.path === getControlPath(error),
199203
) ?? [];
200204

201-
const allErrorsFiltered =
202-
errorsAtControl.length > 0 &&
203-
errorsAtControl.every(
204-
(error) => error.keyword && filterKeywords.includes(error.keyword),
205-
);
206-
207-
return allErrorsFiltered ? '' : input.control.value.errors;
205+
// Filter out errors that match the filterKeywords, keep the rest
206+
const errorsToShow = errorsAtControl.filter(
207+
(error) => !error.keyword || !filterKeywords.includes(error.keyword),
208+
);
209+
// If no errors were filtered out (all errors remain), return original errors string
210+
if (errorsToShow.length === errorsAtControl.length) {
211+
return input.control.value.errors;
212+
}
213+
214+
const t = getTranslator()({ jsonforms });
215+
const te = getErrorTranslator()({ jsonforms });
216+
217+
return getCombinedErrorMessage(
218+
errorsToShow,
219+
te,
220+
t,
221+
input.control.value.schema,
222+
input.control.value.uischema,
223+
input.control.value.path,
224+
);
208225
}
209226

210227
// default, all errors are filtered
@@ -410,13 +427,31 @@ export const useVuetifyArrayControl = <
410427
return `${labelValue}`;
411428
};
412429
const filteredChildErrors = computed(() => {
430+
if (
431+
!input.control.value.childErrors ||
432+
input.control.value.childErrors.length === 0 ||
433+
!appliedOptions.value.enableFilterErrorsBeforeTouch
434+
) {
435+
return input.control.value.childErrors;
436+
}
437+
413438
// supress childErrors unless touch filtering is disabled
414439
// otherwise all child errors will show, irrespective of their control touch state
415-
const filtered: ErrorObject[] = appliedOptions.value
416-
?.enableFilterErrorsBeforeTouch
417-
? []
418-
: input.control.value.childErrors;
419-
return filtered;
440+
441+
const filterKeywords = appliedOptions.value.filterErrorKeywordsBeforeTouch;
442+
443+
// Filtering is enabled - check if specific keywords are configured
444+
if (Array.isArray(filterKeywords) && filterKeywords.length > 0) {
445+
// Granular filtering: only hide specific error keywords
446+
const errorsToShow = input.control.value.childErrors.filter(
447+
(error) => !error.keyword || !filterKeywords.includes(error.keyword),
448+
);
449+
450+
return errorsToShow;
451+
}
452+
453+
// default, all child errors are filtered
454+
return [];
420455
});
421456

422457
const jsonforms = inject<JsonFormsSubStates>('jsonforms');

0 commit comments

Comments
 (0)