Skip to content

Commit

Permalink
netteForms: uses the submitter property
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 22, 2024
1 parent 0011b88 commit 4090f3d
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions src/assets/formValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ export class FormValidator {

this.formErrors = [];

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

form.addEventListener('submit', (e) => {
if (!this.validateForm(form)) {
if (!this.validateForm(form.submitter || form)) {
e.stopPropagation();
e.preventDefault();
}
Expand All @@ -453,17 +453,6 @@ export class FormValidator {
this.#onDocumentReady(() => {
Array.from(document.forms)
.forEach((form) => this.initForm(form));

document.body.addEventListener('click', (e) => {
let target = e.target as FormElement;
while (target) {
if (target.form && target.type in { submit: 1, image: 1 }) {
target.form['nette-submittedBy'] = target;
break;
}
target = target.parentNode as FormElement;
}
});
});
}
}

0 comments on commit 4090f3d

Please sign in to comment.