mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
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.
This commit is contained in:
parent
66346d04bf
commit
c3b282fceb
14
ui/jquery.ui.autocomplete.js
vendored
14
ui/jquery.ui.autocomplete.js
vendored
@ -28,7 +28,9 @@ $.widget( "ui.autocomplete", {
|
|||||||
},
|
},
|
||||||
_create: function() {
|
_create: function() {
|
||||||
var self = this,
|
var self = this,
|
||||||
doc = this.element[ 0 ].ownerDocument;
|
doc = this.element[ 0 ].ownerDocument,
|
||||||
|
suppressKeyPress;
|
||||||
|
|
||||||
this.element
|
this.element
|
||||||
.addClass( "ui-autocomplete-input" )
|
.addClass( "ui-autocomplete-input" )
|
||||||
.attr( "autocomplete", "off" )
|
.attr( "autocomplete", "off" )
|
||||||
@ -43,6 +45,7 @@ $.widget( "ui.autocomplete", {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suppressKeyPress = false;
|
||||||
var keyCode = $.ui.keyCode;
|
var keyCode = $.ui.keyCode;
|
||||||
switch( event.keyCode ) {
|
switch( event.keyCode ) {
|
||||||
case keyCode.PAGE_UP:
|
case keyCode.PAGE_UP:
|
||||||
@ -65,6 +68,9 @@ $.widget( "ui.autocomplete", {
|
|||||||
case keyCode.NUMPAD_ENTER:
|
case keyCode.NUMPAD_ENTER:
|
||||||
// when menu is open and has focus
|
// when menu is open and has focus
|
||||||
if ( self.menu.active ) {
|
if ( self.menu.active ) {
|
||||||
|
// #6055 - Opera still allows the keypress to occur
|
||||||
|
// which causes forms to submit
|
||||||
|
suppressKeyPress = true;
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
//passthrough - ENTER and TAB both select the current element
|
//passthrough - ENTER and TAB both select the current element
|
||||||
@ -91,6 +97,12 @@ $.widget( "ui.autocomplete", {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.bind( "keypress.autocomplete", function( event ) {
|
||||||
|
if ( suppressKeyPress ) {
|
||||||
|
suppressKeyPress = false;
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
})
|
||||||
.bind( "focus.autocomplete", function() {
|
.bind( "focus.autocomplete", function() {
|
||||||
if ( self.options.disabled ) {
|
if ( self.options.disabled ) {
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user