From b1341c5f61cd4169f8b7665f08767ca5b7eb5099 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 10 Jul 2020 14:35:19 +0200 Subject: [PATCH] netteForms: toggle event listeners are added only once --- src/assets/netteForms.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/assets/netteForms.js b/src/assets/netteForms.js index d98ea2da0..e42cfe969 100644 --- a/src/assets/netteForms.js +++ b/src/assets/netteForms.js @@ -31,6 +31,7 @@ var Nette = {}; var preventFiltering = {}; var formToggles = {}; + var toggleListeners = new window.WeakMap(); Nette.formErrors = []; Nette.version = '3.0'; @@ -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); }, @@ -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); } } }