aboutsummaryrefslogtreecommitdiffstats
path: root/ui/jquery.ui.autocomplete.js
diff options
context:
space:
mode:
authorDmitry Petrov <dpetroff@gmail.com>2010-10-06 10:24:03 -0400
committerScott González <scott.gonzalez@gmail.com>2010-10-06 10:24:03 -0400
commitc3b282fceb8b5161c013575bf01c652d6573d72e (patch)
tree59f77b385184e5ef849eb7b457b2ebc6f535c56f /ui/jquery.ui.autocomplete.js
parent66346d04bfa4e9a80ae25a670ea06d9ea7a48e4d (diff)
downloadjquery-ui-c3b282fceb8b5161c013575bf01c652d6573d72e.tar.gz
jquery-ui-c3b282fceb8b5161c013575bf01c652d6573d72e.zip
Autocomplete: Prevent keypress events caused by enter key when selecting an item. Fixes #6055 - Autocomplete: Selecting an item by pressing enter submits the form in Opera.
Diffstat (limited to 'ui/jquery.ui.autocomplete.js')
-rw-r--r--ui/jquery.ui.autocomplete.js14
1 files changed, 13 insertions, 1 deletions
diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js
index 6c4492370..8b41a24dc 100644
--- a/ui/jquery.ui.autocomplete.js
+++ b/ui/jquery.ui.autocomplete.js
@@ -28,7 +28,9 @@ $.widget( "ui.autocomplete", {
},
_create: function() {
var self = this,
- doc = this.element[ 0 ].ownerDocument;
+ doc = this.element[ 0 ].ownerDocument,
+ suppressKeyPress;
+
this.element
.addClass( "ui-autocomplete-input" )
.attr( "autocomplete", "off" )
@@ -43,6 +45,7 @@ $.widget( "ui.autocomplete", {
return;
}
+ suppressKeyPress = false;
var keyCode = $.ui.keyCode;
switch( event.keyCode ) {
case keyCode.PAGE_UP:
@@ -65,6 +68,9 @@ $.widget( "ui.autocomplete", {
case keyCode.NUMPAD_ENTER:
// when menu is open and has focus
if ( self.menu.active ) {
+ // #6055 - Opera still allows the keypress to occur
+ // which causes forms to submit
+ suppressKeyPress = true;
event.preventDefault();
}
//passthrough - ENTER and TAB both select the current element
@@ -91,6 +97,12 @@ $.widget( "ui.autocomplete", {
break;
}
})
+ .bind( "keypress.autocomplete", function( event ) {
+ if ( suppressKeyPress ) {
+ suppressKeyPress = false;
+ event.preventDefault();
+ }
+ })
.bind( "focus.autocomplete", function() {
if ( self.options.disabled ) {
return;