diff options
author | Nathan Friend <nathan@gitlab.com> | 2019-05-17 20:05:15 +0300 |
---|---|---|
committer | Nathan Friend <nathan@gitlab.com> | 2019-05-17 20:05:15 +0300 |
commit | 2a4a732db94652a131aae0fc57801a8f09fabead (patch) | |
tree | b8a201b60826683c8d262d590e2a79d2b7d8cc26 /app/assets/javascripts/dirty_submit | |
parent | 913bc9649b012b178ef1acb9ef254fcc565be248 (diff) |
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.)
Diffstat (limited to 'app/assets/javascripts/dirty_submit')
-rw-r--r-- | app/assets/javascripts/dirty_submit/dirty_submit_form.js | 11 |
1 files changed, 8 insertions, 3 deletions
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); |