[Rt-commit] rt branch 5.0/prevent-ticket-double-click created. rt-5.0.4-230-gb152bada65

BPS Git Server git at git.bestpractical.com
Tue Sep 26 15:26:47 UTC 2023


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/prevent-ticket-double-click has been created
        at  b152bada65a14f0c476df04ed5816ce3cc0fa4fb (commit)

- Log -----------------------------------------------------------------
commit b152bada65a14f0c476df04ed5816ce3cc0fa4fb
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Tue Sep 26 11:22:12 2023 -0400

    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.

diff --git a/share/static/js/util.js b/share/static/js/util.js
index 1c8a1aa6aa..e4e7931e92 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-is-submitting')) {
+                e.preventDefault();
+            }
+
+            // Add class to hook our visual indicator on
+            form.addClass('rt-is-submitting');
+        });
+    });
 });
 
 function filterSearchResults () {

-----------------------------------------------------------------------


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list