From 5ba03ba3599bae4f73e8ddc874f40b2fa9b4bc29 Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 7 Feb 2022 21:50:28 -0600 Subject: [PATCH] replacements: fix submit button not working in Chrome. Fix the submit button in the post replacement dialog doing nothing in Chrome. When the submit button in a dialog box is clicked, we tried to fire a 'submit' event on the form to submit it. Apparently this no longer works in Chrome. `requestSubmit` is the modern way to programmatically submit a form, but it's not supported by Safari, or by versions of Firefox or Chrome released before 2019-2020. https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/requestSubmit https://caniuse.com/mdn-api_htmlformelement_requestsubmit --- app/javascript/src/javascripts/utility.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/javascript/src/javascripts/utility.js b/app/javascript/src/javascripts/utility.js index 4cbe892ac..940be0642 100644 --- a/app/javascript/src/javascripts/utility.js +++ b/app/javascript/src/javascripts/utility.js @@ -61,7 +61,13 @@ Utility.dialog = function(title, html) { buttons: { "Submit": function() { let form = $dialog.find("form").get(0); - Rails.fire(form, "submit"); + + if (form.requestSubmit) { + form.requestSubmit(); + } else { + form.submit(); + Rails.fire(form, "submit"); + } }, "Cancel": function() { $dialog.dialog("close");