Skip to content

Commit

Permalink
Remove submit blocking class on back button push
Browse files Browse the repository at this point in the history
9f85120 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.
  • Loading branch information
richieri-bps committed Sep 24, 2024
1 parent 6df44fa commit 84f996b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions share/static/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 84f996b

Please sign in to comment.