Skip to content

Commit

Permalink
Merge pull request #65 from LiteracyFanatic/fix-messages-in-watch-mode
Browse files Browse the repository at this point in the history
Properly scan messages when the mutated element is a descendant of a form
  • Loading branch information
haacked authored Sep 13, 2023
2 parents 96a527d + d2b4570 commit 6dd5954
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,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 instanceof Element) ? root.closest('form') : null;
if (containingForm) {
forms.push(containingForm);
}

for (let form of forms) {
let validationMessageElements = Array.from(form.querySelectorAll<HTMLElement>('[data-valmsg-for]'));
Expand Down

0 comments on commit 6dd5954

Please sign in to comment.