Skip to content

Commit

Permalink
Prevent double-clicking from submitting forms multiple times
Browse files Browse the repository at this point in the history
Some users double-click form buttons rather than single
clicking as expected and on some forms in some browsers,
this can cause double updates. For example, double clicking
on a ticket comment/reply can post the response twice.

Other forms such as searches might just run the search
twice, using extra server resources needlessly.

Allow all forms to be submitted only once by adding a
CSS class as a flag to indicate the form has been
submitted.
  • Loading branch information
cbrandtbuffalo committed Sep 27, 2023
1 parent 45aaf25 commit 9f85120
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions share/static/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,22 @@ jQuery(function() {
);
return false;
});

// Submit all forms only once.
// This stops all forms of double-clicking or double
// enter/return key.
jQuery('form').each(function() {
var form = jQuery(this);
form.on('submit', function (e) {
// Prevent if already submitting
if (form.hasClass('rt-form-submitted')) {
e.preventDefault();
}

// Add class to hook our visual indicator on
form.addClass('rt-form-submitted');
});
});
});

function filterSearchResults () {
Expand Down

0 comments on commit 9f85120

Please sign in to comment.