From 9f8512096c926d0447fd3b29f67943dde183f910 Mon Sep 17 00:00:00 2001 From: Jim Brandt Date: Tue, 26 Sep 2023 11:22:12 -0400 Subject: [PATCH] Prevent double-clicking from submitting forms multiple times 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. --- share/static/js/util.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/share/static/js/util.js b/share/static/js/util.js index 1c8a1aa6aa8..6d8ddf76c38 100644 --- a/share/static/js/util.js +++ b/share/static/js/util.js @@ -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 () {