Skip to content

Commit

Permalink
Autocomplete: Avoid handling keypress when keydown modified the searc…
Browse files Browse the repository at this point in the history
…h term. Fixes #7799 - Autocomplete regression - Cannot type '&' in IE and Chrome.
  • Loading branch information
scottgonzalez committed Oct 17, 2011
1 parent d4d8d74 commit 63374dc
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions ui/jquery.ui.autocomplete.js
Expand Up @@ -48,7 +48,15 @@ $.widget( "ui.autocomplete", {
_create: function() { _create: function() {
var self = this, var self = this,
doc = this.element[ 0 ].ownerDocument, doc = this.element[ 0 ].ownerDocument,
// Some browsers only repeat keydown events, not keypress events,
// so we use the suppressKeyPress flag to determine if we've already
// handled the keydown event. #7269
// Unfortunately the code for & in keypress is the same as the up arrow,
// so we use the suppressKeyPressRepeat flag to avoid handling keypress
// events when we know the keydown event was used to modify the
// search term. #7799
suppressKeyPress, suppressKeyPress,
suppressKeyPressRepeat,
suppressInput; suppressInput;


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


suppressKeyPress = false; suppressKeyPress = false;
suppressInput = false; suppressInput = false;
suppressKeyPressRepeat = false;
var keyCode = $.ui.keyCode; var keyCode = $.ui.keyCode;
switch( event.keyCode ) { switch( event.keyCode ) {
case keyCode.PAGE_UP: case keyCode.PAGE_UP:
Expand Down Expand Up @@ -116,6 +126,7 @@ $.widget( "ui.autocomplete", {
} }
break; break;
default: default:
suppressKeyPressRepeat = true;
// search timeout should be triggered before the input value is changed // search timeout should be triggered before the input value is changed
self._searchTimeout( event ); self._searchTimeout( event );
break; break;
Expand All @@ -127,6 +138,9 @@ $.widget( "ui.autocomplete", {
event.preventDefault(); event.preventDefault();
return; return;
} }
if ( suppressKeyPressRepeat ) {
return;
}


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

1 comment on commit 63374dc

@jzaefferer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh

Please sign in to comment.