Skip to content

Commit 4090f3d

Browse files
committed
netteForms: uses the submitter property
1 parent 0011b88 commit 4090f3d

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

src/assets/formValidator.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ export class FormValidator {
161161

162162
this.formErrors = [];
163163

164-
if (form['nette-submittedBy'] && form['nette-submittedBy'].getAttribute('formnovalidate') !== null) {
165-
let scopeArr = JSON.parse(form['nette-submittedBy'].getAttribute('data-nette-validation-scope') ?? '[]') as string[];
164+
if (sender.getAttribute('formnovalidate') !== null) {
165+
let scopeArr = JSON.parse(sender.getAttribute('data-nette-validation-scope') ?? '[]') as string[];
166166
if (scopeArr.length) {
167167
scope = new RegExp('^(' + scopeArr.join('-|') + '-)');
168168
} else {
@@ -437,7 +437,7 @@ export class FormValidator {
437437
form.noValidate = true;
438438

439439
form.addEventListener('submit', (e) => {
440-
if (!this.validateForm(form)) {
440+
if (!this.validateForm(form.submitter || form)) {
441441
e.stopPropagation();
442442
e.preventDefault();
443443
}
@@ -453,17 +453,6 @@ export class FormValidator {
453453
this.#onDocumentReady(() => {
454454
Array.from(document.forms)
455455
.forEach((form) => this.initForm(form));
456-
457-
document.body.addEventListener('click', (e) => {
458-
let target = e.target as FormElement;
459-
while (target) {
460-
if (target.form && target.type in { submit: 1, image: 1 }) {
461-
target.form['nette-submittedBy'] = target;
462-
break;
463-
}
464-
target = target.parentNode as FormElement;
465-
}
466-
});
467456
});
468457
}
469458
}

0 commit comments

Comments
 (0)