diff options
author | Chris Seelus <chris@imeos.com> | 2018-07-22 01:48:25 +0200 |
---|---|---|
committer | Chris Seelus <chris@imeos.com> | 2018-08-18 19:31:39 +0200 |
commit | 880f977925601c3afe125274b5cc95e150341a9f (patch) | |
tree | 840a02cce5ac90986faac4dc31ad6f5c950f3542 /activestorage/app/assets | |
parent | 87d5415f0aa3e6f9f74f645a47370dd854375a1a (diff) | |
download | rails-880f977925601c3afe125274b5cc95e150341a9f.tar.gz rails-880f977925601c3afe125274b5cc95e150341a9f.tar.bz2 rails-880f977925601c3afe125274b5cc95e150341a9f.zip |
Enable multiple submit buttons for Active Storage forms
Diffstat (limited to 'activestorage/app/assets')
-rw-r--r-- | activestorage/app/assets/javascripts/activestorage.js | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/activestorage/app/assets/javascripts/activestorage.js b/activestorage/app/assets/javascripts/activestorage.js index d3fd795a3a..8a51805960 100644 --- a/activestorage/app/assets/javascripts/activestorage.js +++ b/activestorage/app/assets/javascripts/activestorage.js @@ -855,14 +855,21 @@ return DirectUploadsController; }(); var processingAttribute = "data-direct-uploads-processing"; + var submitButtonsByForm = new WeakMap; var started = false; function start() { if (!started) { started = true; + document.addEventListener("click", didClick, true); document.addEventListener("submit", didSubmitForm); document.addEventListener("ajax:before", didSubmitRemoteElement); } } + function didClick(event) { + if (event.target.tagName == "INPUT" && event.target.type == "submit" && event.target.form) { + submitButtonsByForm.set(event.target.form, event.target); + } + } function didSubmitForm(event) { handleFormSubmissionEvent(event); } @@ -894,7 +901,8 @@ } } function submitForm(form) { - var button = findElement(form, "input[type=submit]"); + var button = submitButtonsByForm.get(form) || findElement(form, "input[type=submit]"); + if (button) { var _button = button, disabled = _button.disabled; button.disabled = false; @@ -909,6 +917,7 @@ button.click(); form.removeChild(button); } + submitButtonsByForm.delete(form); } function disable(input) { input.disabled = true; |