Skip to content

Commit

Permalink
netteForms: toggle event listeners are added only once
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jul 13, 2020
1 parent 4d07ae2 commit b1341c5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/assets/netteForms.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
var Nette = {};
var preventFiltering = {};
var formToggles = {};
var toggleListeners = new window.WeakMap();

Nette.formErrors = [];
Nette.version = '3.0';
Expand Down Expand Up @@ -592,7 +593,6 @@
emptyOptional = emptyOptional === undefined ? !Nette.validateRule(elem, ':filled', null, value) : emptyOptional;

var has = false,
handled = [],
handler = function () {
Nette.toggleForm(elem.form, elem);
},
Expand Down Expand Up @@ -634,9 +634,9 @@
els = curElem.tagName ? curElem.form.elements : curElem;

for (var i = 0; i < els.length; i++) {
if (els[i].name === name && handled.indexOf(els[i]) < 0) {
if (els[i].name === name && !toggleListeners.has(els[i])) {
els[i].addEventListener('change', handler);
handled.push(els[i]);
toggleListeners.set(els[i], null);
}
}
}
Expand Down

0 comments on commit b1341c5

Please sign in to comment.