- Patch #216059 by nedjo, theborg, karens, goba, webchick et al: AHAH triggered by text input enter key press breaks autocomplete.

merge-requests/26/head
Dries Buytaert 2008-02-12 13:52:33 +00:00
parent 0f1085201e
commit 1d390ef36c
2 changed files with 21 additions and 1 deletions

View File

@ -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'],

View File

@ -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;
}
});
}
};
/**