Index: includes/ajax.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/ajax.inc,v retrieving revision 1.41 diff -u -p -r1.41 ajax.inc --- includes/ajax.inc 23 Dec 2010 04:26:31 -0000 1.41 +++ includes/ajax.inc 25 Dec 2010 19:44:02 -0000 @@ -587,13 +587,24 @@ function ajax_pre_render_element($elemen case 'submit': case 'button': case 'image_button': - // Use the mousedown instead of the click event because form - // submission via pressing the enter key triggers a click event on - // submit inputs, inappropriately triggering AJAX behaviors. + // Pressing the ENTER key within a textfield triggers the click event of + // the form's first submit button. Triggering AJAX in this situation + // leads to problems, like breaking autocomplete textfields, so we bind + // to mousedown instead of click. + // @see http://drupal.org/node/216059 $element['#ajax']['event'] = 'mousedown'; - // Attach an additional event handler so that AJAX behaviors - // can be triggered still via keyboard input. + // Retain keyboard accessibility by setting 'keypress'. This causes + // ajax.js to trigger 'event' when SPACE or ENTER are pressed while the + // button has focus. $element['#ajax']['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['#ajax']['prevent'] = 'click'; break; case 'password': Index: misc/ajax.js =================================================================== RCS file: /cvs/drupal/drupal/misc/ajax.js,v retrieving revision 1.35 diff -u -p -r1.35 ajax.js --- misc/ajax.js 23 Dec 2010 04:26:31 -0000 1.35 +++ misc/ajax.js 25 Dec 2010 19:44:03 -0000 @@ -183,10 +183,17 @@ Drupal.ajax = function (base, element, e // can be triggered through keyboard input as well as e.g. a mousedown // action. if (element_settings.keypress) { - $(element_settings.element).keypress(function (event) { + $(ajax.element).keypress(function (event) { return ajax.keypressResponse(this, event); }); } + + // If necessary, prevent the browser default action of an additional event. + // For example, prevent the browser default action of a click, even if the + // AJAX behavior binds to mousedown. + if (element_settings.prevent) { + $(ajax.element).bind(element_settings.prevent, false); + } }; /**