form: fix action sent after navigating away and back again

This commit is contained in:
Paul Chavard 2018-07-02 09:35:05 +00:00 committed by Pierre de La Morinerie
parent 68bcbf7557
commit 2a8dbf521d

View file

@ -44,13 +44,17 @@ addEventListener("direct-upload:end", function (event) {
element.classList.add("direct-upload--complete");
});
addEventListener('load', function() {
addEventListener('turbolinks:load', function() {
var submitButtons = document.querySelectorAll('form button[type=submit][data-action]');
var hiddenInput = document.querySelector('form input[type=hidden][name=submit_action]');
submitButtons = [].slice.call(submitButtons);
submitButtons.forEach(function(button) {
button.addEventListener('click', function() {
// Active Storage will intercept the form.submit event to upload
// the attached files, and then fire the submit action again but forgetting
// which button was clicked. So we manually set the type of action that trigerred
// the form submission.
hiddenInput.value = button.getAttribute('data-action');
});
});