Commit 1d390ef3 authored by Dries's avatar Dries

- Patch #216059 by nedjo, theborg, karens, goba, webchick et al: AHAH...

- Patch #216059 by nedjo, theborg, karens, goba, webchick et al: AHAH triggered by text input enter key press breaks autocomplete.
parent 0f108520
......@@ -1749,7 +1749,13 @@ function form_expand_ahah($element) {
case 'submit':
case 'button':
case 'image_button':
$element['#ahah']['event'] = 'click';
// 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 AHAH behaviors.
$element['#ahah']['event'] = 'mousedown';
// Attach an additional event handler so that AHAH behaviours
// can be triggered still via keyboard input.
$element['#ahah']['keypress'] = TRUE;
break;
case 'password':
case 'textfield':
......@@ -1773,6 +1779,7 @@ function form_expand_ahah($element) {
$ahah_binding = array(
'url' => url($element['#ahah']['path']),
'event' => $element['#ahah']['event'],
'keypress' => empty($element['#ahah']['keypress']) ? NULL : $element['#ahah']['keypress'],
'wrapper' => empty($element['#ahah']['wrapper']) ? NULL : $element['#ahah']['wrapper'],
'selector' => empty($element['#ahah']['selector']) ? '#'. $element['#id'] : $element['#ahah']['selector'],
'effect' => empty($element['#ahah']['effect']) ? 'none' : $element['#ahah']['effect'],
......
......@@ -38,6 +38,7 @@ Drupal.ahah = function(base, element_settings) {
this.element = element_settings.element;
this.selector = element_settings.selector;
this.event = element_settings.event;
this.keypress = element_settings.keypress;
this.url = element_settings.url;
this.wrapper = '#'+ element_settings.wrapper;
this.effect = element_settings.effect;
......@@ -98,6 +99,18 @@ Drupal.ahah = function(base, element_settings) {
$(element_settings.element).parents('form').ajaxSubmit(options);
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.
if (element_settings.keypress) {
$(element_settings.element).keypress(function(event) {
// Detect enter key.
if (event.keyCode == 13) {
$(element_settings.element).trigger(element_settings.event);
return false;
}
});
}
};
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment