Skip to content

Commit

Permalink
Autocomplete: Prevent keypress events caused by enter key when select…
Browse files Browse the repository at this point in the history
…ing an item. Fixes #6055 - Autocomplete: Selecting an item by pressing enter submits the form in Opera.
  • Loading branch information
can3p authored and scottgonzalez committed Oct 6, 2010
1 parent 66346d0 commit c3b282f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion ui/jquery.ui.autocomplete.js
Expand Up @@ -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" )
Expand All @@ -43,6 +45,7 @@ $.widget( "ui.autocomplete", {
return;
}

suppressKeyPress = false;
var keyCode = $.ui.keyCode;
switch( event.keyCode ) {
case keyCode.PAGE_UP:
Expand All @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit c3b282f

Please sign in to comment.