summaryrefslogtreecommitdiff
path: root/includes/ajax.inc
diff options
context:
space:
mode:
Diffstat (limited to 'includes/ajax.inc')
-rw-r--r--includes/ajax.inc21
1 files changed, 16 insertions, 5 deletions
diff --git a/includes/ajax.inc b/includes/ajax.inc
index 41c69832a..6111d3784 100644
--- a/includes/ajax.inc
+++ b/includes/ajax.inc
@@ -619,13 +619,24 @@ function ajax_pre_render_element($element) {
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':