Skip to content

Commit

Permalink
Autocomplete: Respect the disabled option. Fixes #5619 - Autocomplete…
Browse files Browse the repository at this point in the history
… widget keeps looking for remote data even when it's disabled.
  • Loading branch information
scottgonzalez committed Jul 30, 2010
1 parent 58ae7ce commit 90caa93
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/unit/autocomplete/autocomplete_options.js
Expand Up @@ -116,6 +116,24 @@ test("delay", function() {
}, 100);
});

test("disabled", function() {
var ac = $("#autocomplete").autocomplete({
source: data,
delay: 0,
disabled: true
});
ac.val("ja").keydown();

same( $(".ui-menu:visible").length, 0 );

stop();
setTimeout(function() {
same( $(".ui-menu:visible").length, 0 );
ac.autocomplete("destroy");
start();
}, 50);
});

test("minLength", function() {
var ac = $("#autocomplete").autocomplete({
source: data
Expand Down
12 changes: 12 additions & 0 deletions ui/jquery.ui.autocomplete.js
Expand Up @@ -39,6 +39,10 @@ $.widget( "ui.autocomplete", {
"aria-haspopup": "true"
})
.bind( "keydown.autocomplete", function( event ) {
if ( self.options.disabled ) {
return;
}

var keyCode = $.ui.keyCode;
switch( event.keyCode ) {
case keyCode.PAGE_UP:
Expand Down Expand Up @@ -88,10 +92,18 @@ $.widget( "ui.autocomplete", {
}
})
.bind( "focus.autocomplete", function() {
if ( self.options.disabled ) {
return;
}

self.selectedItem = null;
self.previous = self.element.val();
})
.bind( "blur.autocomplete", function( event ) {
if ( self.options.disabled ) {
return;
}

clearTimeout( self.searching );
// clicks on the menu (or a button to trigger a search) will cause a blur event
self.closing = setTimeout(function() {
Expand Down

0 comments on commit 90caa93

Please sign in to comment.