Skip to content

Commit

Permalink
netteForms: processes only elements with 'data-nette-rules'
Browse files Browse the repository at this point in the history
also eliminates validating each <input> in the checkboxlist separately
  • Loading branch information
dg committed May 5, 2024
1 parent 1de969c commit ce1ad59
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions src/assets/netteForms.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
*/
Nette.validateForm = function (sender, onlyCheck) {
let form = sender.form || sender,
scope = false;
scope;

Nette.formErrors = [];

Expand All @@ -230,31 +230,20 @@
}
}

let radios = {};

for (let elem of form.elements) {
if (elem.willValidate && elem.validity.badInput) {
elem.reportValidity();
return false;
}
}

for (let elem of form.elements) {
if (elem.tagName && !(elem.tagName.toLowerCase() in {input: 1, select: 1, textarea: 1, button: 1})) {
continue;

} else if (elem.type === 'radio') {
if (radios[elem.name]) {
continue;
}
radios[elem.name] = true;
}

if ((scope && !elem.name.replace(/]\[|\[|]|$/g, '-').match(scope)) || Nette.isDisabled(elem)) {
continue;
}

if (!Nette.validateControl(elem, null, onlyCheck) && !Nette.formErrors.length) {
for (let elem of Array.from(form.elements)) {
if (elem.getAttribute('data-nette-rules')
&& (!scope || elem.name.replace(/]\[|\[|]|$/g, '-').match(scope))
&& !Nette.isDisabled(elem)
&& !Nette.validateControl(elem, null, onlyCheck)
&& !Nette.formErrors.length
) {
return false;
}
}
Expand Down Expand Up @@ -600,9 +589,9 @@
*/
Nette.toggleForm = function (form, event) {
formToggles = {};
for (let i = 0; i < form.elements.length; i++) {
if (form.elements[i].tagName.toLowerCase() in {input: 1, select: 1, textarea: 1, button: 1}) {
Nette.toggleControl(form.elements[i], null, null, !event);
for (let elem of Array.from(form.elements)) {
if (elem.getAttribute('data-nette-rules')) {
Nette.toggleControl(elem, null, null, !event);
}
}

Expand Down

0 comments on commit ce1ad59

Please sign in to comment.