Skip to content

Commit 63374dc

Browse files
committed
Autocomplete: Avoid handling keypress when keydown modified the search term. Fixes #7799 - Autocomplete regression - Cannot type '&' in IE and Chrome.
1 parent d4d8d74 commit 63374dc

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

ui/jquery.ui.autocomplete.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,15 @@ $.widget( "ui.autocomplete", {
4848
_create: function() {
4949
var self = this,
5050
doc = this.element[ 0 ].ownerDocument,
51+
// Some browsers only repeat keydown events, not keypress events,
52+
// so we use the suppressKeyPress flag to determine if we've already
53+
// handled the keydown event. #7269
54+
// Unfortunately the code for & in keypress is the same as the up arrow,
55+
// so we use the suppressKeyPressRepeat flag to avoid handling keypress
56+
// events when we know the keydown event was used to modify the
57+
// search term. #7799
5158
suppressKeyPress,
59+
suppressKeyPressRepeat,
5260
suppressInput;
5361

5462
this.valueMethod = this.element[ this.element.is( "input,textarea" ) ? "val" : "text" ];
@@ -66,11 +74,13 @@ $.widget( "ui.autocomplete", {
6674
if ( self.options.disabled || self.element.prop( "readOnly" ) ) {
6775
suppressKeyPress = true;
6876
suppressInput = true;
77+
suppressKeyPressRepeat = true;
6978
return;
7079
}
7180

7281
suppressKeyPress = false;
7382
suppressInput = false;
83+
suppressKeyPressRepeat = false;
7484
var keyCode = $.ui.keyCode;
7585
switch( event.keyCode ) {
7686
case keyCode.PAGE_UP:
@@ -116,6 +126,7 @@ $.widget( "ui.autocomplete", {
116126
}
117127
break;
118128
default:
129+
suppressKeyPressRepeat = true;
119130
// search timeout should be triggered before the input value is changed
120131
self._searchTimeout( event );
121132
break;
@@ -127,6 +138,9 @@ $.widget( "ui.autocomplete", {
127138
event.preventDefault();
128139
return;
129140
}
141+
if ( suppressKeyPressRepeat ) {
142+
return;
143+
}
130144

131145
// replicate some key handlers to allow them to repeat in Firefox and Opera
132146
var keyCode = $.ui.keyCode;

0 commit comments

Comments
 (0)