[Rt-commit] rt branch, 4.2/avoid-disabling-submit-buttons, created. rt-4.2.3-87-gff7f8e3

? sunnavy sunnavy at bestpractical.com
Mon Apr 28 07:51:58 EDT 2014


The branch, 4.2/avoid-disabling-submit-buttons has been created
        at  ff7f8e312107c5e05af28bbd324c777ed79caa20 (commit)

- Log -----------------------------------------------------------------
commit ff7f8e312107c5e05af28bbd324c777ed79caa20
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Apr 22 22:35:50 2014 +0800

    refactor "prevent double submission" js code to not disable submit buttons
    
    if you are going back to a page which contains those disabled buttons, they
    stay disabled and clicking them results nothing.  see also #27489
    
    this commit makes sure the forms in page(even if you are going back to it)
    could be submitted

diff --git a/share/static/js/forms.js b/share/static/js/forms.js
index 57132be..3c6f9b9 100644
--- a/share/static/js/forms.js
+++ b/share/static/js/forms.js
@@ -1,13 +1,18 @@
 jQuery(function() {
-  jQuery('form').submit(function() {
-    jQuery(this).find('input[type="submit"]').attr('disabled','disabled');
-    return true;
-  })
-  jQuery('input[type="submit"]').click(function() {
-    var $this = jQuery(this);
-    var name = $this.attr('name');
-    if (!name) { return true; }
-    $this.after( jQuery('<input/>', {type: "hidden", name: name, value: $this.val()} ) );
-    return true;
-  })
-});
\ No newline at end of file
+    // reset form submit info when user goes backward or forward for Safari
+    // other browsers don't need this trick and they can work directly.
+    if ( window.addEventListener ) {
+        window.addEventListener("popstate", function(e) {
+            jQuery('form').data('submitted', false);
+        });
+    }
+
+    jQuery('form').submit(function(e) {
+        var form = jQuery(this);
+        if (form.data('submitted') === true) {
+            e.preventDefault();
+        } else {
+            form.data('submitted', true);
+        }
+    });
+});

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


More information about the rt-commit mailing list