From 2a4a732db94652a131aae0fc57801a8f09fabead Mon Sep 17 00:00:00 2001 From: Nathan Friend Date: Fri, 17 May 2019 14:05:15 -0300 Subject: Fix throttling issue in form dirty checking This commit fixes an issue that was causing the "Save changes" button to be incorrectly enabled or disabled when changes were made to a form. (Specifically, some of the subsections in the project settings pages.) --- app/assets/javascripts/dirty_submit/dirty_submit_form.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'app/assets/javascripts/dirty_submit') diff --git a/app/assets/javascripts/dirty_submit/dirty_submit_form.js b/app/assets/javascripts/dirty_submit/dirty_submit_form.js index 765969daa32..0fcaec9531c 100644 --- a/app/assets/javascripts/dirty_submit/dirty_submit_form.js +++ b/app/assets/javascripts/dirty_submit/dirty_submit_form.js @@ -21,10 +21,15 @@ class DirtySubmitForm { } registerListeners() { - const throttledUpdateDirtyInput = _.throttle( - event => this.updateDirtyInput(event), - DirtySubmitForm.THROTTLE_DURATION, + const getThrottledHandlerForInput = _.memoize(() => + _.throttle(event => this.updateDirtyInput(event), DirtySubmitForm.THROTTLE_DURATION), ); + + const throttledUpdateDirtyInput = event => { + const throttledHandler = getThrottledHandlerForInput(event.target.name); + throttledHandler(event); + }; + this.form.addEventListener('input', throttledUpdateDirtyInput); this.form.addEventListener('change', throttledUpdateDirtyInput); $(this.form).on('change.select2', throttledUpdateDirtyInput); -- cgit v1.2.1