Skip to content

Commit cca34e7

Browse files
committed
Error path fix.
1 parent 319552b commit cca34e7

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/lib/client/superForm.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ export function superForm<
810810
const el = formElement.querySelector<HTMLElement>(`[name="${name}"]`);
811811
if (el) {
812812
const message = 'validationMessage' in el ? String(el.validationMessage) : '';
813-
validity.set(path.join(), { el, message });
813+
validity.set(path.join('.'), { el, message });
814814
updateCustomValidity(el, undefined);
815815
}
816816
}
@@ -835,15 +835,17 @@ export function superForm<
835835
traversePaths(errors, (error) => {
836836
if (!Array.isArray(error.value)) return;
837837

838-
let joinedPath = error.path.join('.');
839-
if (joinedPath.endsWith('._errors')) {
840-
joinedPath = joinedPath.substring(0, -8);
838+
const currentPath = [...error.path];
839+
if (currentPath[currentPath.length - 1] == '_errors') {
840+
currentPath.pop();
841841
}
842842

843843
function addError() {
844844
//console.log('Adding error', `[${error.path.join('.')}]`, error.value); //debug
845845
setPaths(output, [error.path], error.value);
846846

847+
const joinedPath = currentPath.join('.');
848+
847849
if (options.customValidity && isEventError && validity.has(joinedPath)) {
848850
const { el, message } = validity.get(joinedPath)!;
849851

@@ -859,9 +861,9 @@ export function superForm<
859861

860862
const isEventError =
861863
error.value &&
862-
paths
863-
.map((path) => path.join('.'))
864-
.some((path) => path.length <= joinedPath.length && path.startsWith(joinedPath));
864+
paths.some((path) => {
865+
return currentPath && path && currentPath.length > 0 && currentPath[0] == path[0];
866+
});
865867

866868
if (isEventError && options.validationMethod == 'oninput') return addError();
867869

0 commit comments

Comments
 (0)