From d7f572081384a48874a21fdd2099d10a1607fe17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sun, 9 Apr 2023 02:11:09 +0200 Subject: [PATCH] fix observeInput logic --- public/static/js/rvr.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/public/static/js/rvr.js b/public/static/js/rvr.js index dcf3d45..ed2ef94 100644 --- a/public/static/js/rvr.js +++ b/public/static/js/rvr.js @@ -158,12 +158,17 @@ var RVR = { document.getElementById('cover').style.visibility = 'hidden'; }, - observeInput: function (input, buttonToToggle) { - if (input.defaultValue !== input.value) { - buttonToToggle.disabled = false; - } else { - buttonToToggle.disabled = true; + observeInput: function (form, observedInputs) { + var anyChanged = false; + + for (var i = 0; i < observedInputs.length; i++) { + var input = form.elements[observedInputs[i]]; + if (input.defaultValue !== input.value) { + anyChanged = true; + } } + + form.elements.submit.disabled = !anyChanged; }, observeInputsInForm: function (form, observedInputs) { @@ -174,12 +179,12 @@ var RVR = { case 'INPUT': case 'TEXTAREA': input.oninput = function () { - RVR.observeInput(this, form.elements.submit); + RVR.observeInput(form, observedInputs); }; break; case 'SELECT': input.onchange = function () { - RVR.observeInput(this, form.elements.submit); + RVR.observeInput(form, observedInputs); }; break; }