From 84f996bbedf9a95972e95dbc483481f70f4deb83 Mon Sep 17 00:00:00 2001 From: Ronaldo Richieri Date: Thu, 19 Sep 2024 13:53:19 -0300 Subject: [PATCH] Remove submit blocking class on back button push 9f8512096c added code to prevent double submits by adding a class when a submit button is clicked. Browser back buttons retrieve a cached page, so that class is still present and users cannot use any submit buttons on the page. It's not possible to detect a back button push directly, but some research confirms the popstate event is fired whenever the browser history is accessed, which happens when back is clicked. In testing, shortcut keys also access history and trigger popstate, so that case should be covered also. However, this event is not fired on WebKit based browsers when the user navigates back using the back button as described in https://bugs.webkit.org/show_bug.cgi?id=248303 So we are added also a listener to the pageshow event to ensure the submit blocking class is removed when the user navigates back on WebKit based browsers. --- share/static/js/util.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/share/static/js/util.js b/share/static/js/util.js index 4b3e746eb42..73176a2391c 100644 --- a/share/static/js/util.js +++ b/share/static/js/util.js @@ -1036,6 +1036,16 @@ jQuery(function() { form.addClass('rt-form-submitted'); }); }); + // Clean up the class when history back button is used, allowing + // the form to be submitted again. + jQuery(window).on('popstate', function(event) { + jQuery('form').removeClass('rt-form-submitted'); + }); + // WebKit based browsers don't fire popstate on back button + // sometimes but they do fire pageshow event. + jQuery(window).on("pageshow", function() { + jQuery('form').removeClass('rt-form-submitted'); + }); }); function filterSearchResults (type) {