in IE 7 submit is followed by an unexpected page refresh
it would be nice if this could be avoided

Comments

HylkeVDS’s picture

Title: unexpected page refresh in IE7 » unexpected page refresh in browsers
Category: task » bug
Status: Active » Needs review

This is actually a very tricky bug that's also in D7 and not IE specific. It's explained here: #634616: Various problems due to AJAX binding to mousedown instead of click

There's a patch for D7 that uses a workaround that I backported to D6 / jquery_update:

Drupal core patch:

Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.265.2.35
diff -u -p -r1.265.2.35 form.inc
--- includes/form.inc   4 Nov 2010 09:55:29 -0000       1.265.2.35
+++ includes/form.inc   3 Feb 2011 15:11:11 -0000
@@ -1802,6 +1802,14 @@ function form_expand_ahah($element) {
         // Attach an additional event handler so that AHAH behaviours
         // can be triggered still via keyboard input.
         $element['#ahah']['keypress'] = TRUE;
+        // Binding to mousedown rather than click means that it is possible to
+        // trigger a click by pressing the mouse, holding the mouse button down
+        // until the AJAX request is complete and the button is re-enabled, and
+        // then releasing the mouse button. Set 'prevent' so that ajax.js binds
+        // an additional handler to prevent such a click from triggering a
+        // non-AJAX form submission. This also prevents a textfield's ENTER
+        // press triggering this button's non-AJAX form submission behavior.
+        $element['#ahah']['prevent'] = 'click';
         break;
       case 'password':
       case 'textfield':
@@ -1832,6 +1840,7 @@ function form_expand_ahah($element) {
       'method'   => empty($element['#ahah']['method']) ? 'replace' : $element['#ahah']['method'],
       'progress' => empty($element['#ahah']['progress']) ? array('type' => 'throbber') : $element['#ahah']['progress'],
       'button'   => isset($element['#executes_submit_callback']) ? array($element['#name'] => $element['#value']) : FALSE,
+      'prevent'  => empty($element['#ahah']['prevent']) ? NULL : $element['#ahah']['prevent'],
     );

     // Convert a simple #ahah[progress] type string into an array.

Juqery update 2.x-dev patch:

Index: replace/ahah.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/jquery_update/replace/Attic/ahah.js,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 ahah.js
--- replace/ahah.js     21 Mar 2009 19:43:51 -0000      1.1.2.1
+++ replace/ahah.js     3 Feb 2011 15:27:35 -0000
@@ -99,6 +99,10 @@ Drupal.ahah = function(base, element_set
     $(element_settings.element).parents('form').ajaxSubmit(options);
     return false;
   });
+  // Prevent certain events from causing a page reload.
+  if (element_settings.prevent) {
+    $(ahah.element).bind(element_settings.prevent, function (event) {return false});
+  }
   // If necessary, enable keyboard submission so that AHAH behaviors
   // can be triggered through keyboard input as well as e.g. a mousedown
   // action.
jvdkolk’s picture

Status: Needs review » Closed (won't fix)

IE7...