summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDries Buytaert2008-02-12 13:52:33 (GMT)
committerDries Buytaert2008-02-12 13:52:33 (GMT)
commit1d390ef36c996a30b462e406f5c63139539df87b (patch)
treeddaa9531db7f777bc6e5446d16b68da68b740366
parent0f1085201e6aeded3119075dd3ef442317c026c2 (diff)
- Patch #216059 by nedjo, theborg, karens, goba, webchick et al: AHAH triggered by text input enter key press breaks autocomplete.
-rw-r--r--includes/form.inc9
-rw-r--r--misc/ahah.js13
2 files changed, 21 insertions, 1 deletions
diff --git a/includes/form.inc b/includes/form.inc
index 473e67b..eb94343 100644
--- a/includes/form.inc
+++ b/includes/form.inc
@@ -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'],
diff --git a/misc/ahah.js b/misc/ahah.js
index 775159d..a098add 100644
--- a/misc/ahah.js
+++ b/misc/ahah.js
@@ -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;
+ }
+ });
+ }
};
/**