From 4bb44e975734f07ba94a4cb279ae1ab181458429 Mon Sep 17 00:00:00 2001 From: Jordan Cannon Date: Mon, 31 Jul 2023 05:01:18 -0500 Subject: [PATCH 1/2] Properly scan messages when the mutated element is a descendant of a form --- src/index.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/index.ts b/src/index.ts index b50ede4..0069233 100644 --- a/src/index.ts +++ b/src/index.ts @@ -535,6 +535,11 @@ export class ValidationService { // we could use 'matches', but that's newer than querySelectorAll so we'll keep it simple and compatible. forms.push(root); } + // If root is the descendant of a form, we want to include that form too. + const containingForm = (root as HTMLElement).closest('form'); + if (containingForm) { + forms.push(containingForm); + } for (let form of forms) { let validationMessageElements = Array.from(form.querySelectorAll('[data-valmsg-for]')); From d2b45708449f135ac7354ee54d165cd55179cfdb Mon Sep 17 00:00:00 2001 From: Jordan Cannon Date: Tue, 1 Aug 2023 15:11:10 -0500 Subject: [PATCH 2/2] Check that type of root is Element before using closest Co-authored-by: Keith Dahlby --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 0069233..024dcb8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -536,7 +536,7 @@ export class ValidationService { forms.push(root); } // If root is the descendant of a form, we want to include that form too. - const containingForm = (root as HTMLElement).closest('form'); + const containingForm = (root instanceof Element) ? root.closest('form') : null; if (containingForm) { forms.push(containingForm); }