Skip to content
Permalink
Browse files

Autocomplete: Fix list traversal bug. Fixes #7269 - autocomplete: hol…

…ding down arrow keys in Firefox does not traverse list

Use keypress event for listening for arrow keys because Firefox
and Opera do not repeat keydown events for these keys.
  • Loading branch information...
treyhunner committed Apr 19, 2011
1 parent 5076f23 commit bdfc6d532c68c092a83461a8b76840719294313f
Showing with 26 additions and 0 deletions.
  1. +26 −0 ui/jquery.ui.autocomplete.js
@@ -53,24 +53,29 @@ $.widget( "ui.autocomplete", {
})
.bind( "keydown.autocomplete", function( event ) {
if ( self.options.disabled || self.element.attr( "readonly" ) ) {
suppressKeyPress = true;
return;
}

suppressKeyPress = false;
var keyCode = $.ui.keyCode;
switch( event.keyCode ) {
case keyCode.PAGE_UP:
suppressKeyPress = true;
self._move( "previousPage", event );
break;
case keyCode.PAGE_DOWN:
suppressKeyPress = true;
self._move( "nextPage", event );
break;
case keyCode.UP:
suppressKeyPress = true;
self._move( "previous", event );
// prevent moving cursor to beginning of text field in some browsers
event.preventDefault();
break;
case keyCode.DOWN:
suppressKeyPress = true;
self._move( "next", event );
// prevent moving cursor to end of text field in some browsers
event.preventDefault();
@@ -112,7 +117,28 @@ $.widget( "ui.autocomplete", {
if ( suppressKeyPress ) {
suppressKeyPress = false;
event.preventDefault();
return;
}

var keyCode = $.ui.keyCode;
switch( event.keyCode ) {
case keyCode.PAGE_UP:
self._move( "previousPage", event );
break;
case keyCode.PAGE_DOWN:
self._move( "nextPage", event );
break;
case keyCode.UP:
self._move( "previous", event );
// prevent moving cursor to beginning of text field in some browsers
event.preventDefault();
break;
case keyCode.DOWN:
self._move( "next", event );
// prevent moving cursor to end of text field in some browsers
event.preventDefault();
break;
}
})
.bind( "focus.autocomplete", function() {
if ( self.options.disabled ) {

0 comments on commit bdfc6d5

Please sign in to comment.
You can’t perform that action at this time.