Skip to content

Commit 90caa93

Browse files
committed
Autocomplete: Respect the disabled option. Fixes #5619 - Autocomplete widget keeps looking for remote data even when it's disabled.
1 parent 58ae7ce commit 90caa93

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

tests/unit/autocomplete/autocomplete_options.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,24 @@ test("delay", function() {
116116
}, 100);
117117
});
118118

119+
test("disabled", function() {
120+
var ac = $("#autocomplete").autocomplete({
121+
source: data,
122+
delay: 0,
123+
disabled: true
124+
});
125+
ac.val("ja").keydown();
126+
127+
same( $(".ui-menu:visible").length, 0 );
128+
129+
stop();
130+
setTimeout(function() {
131+
same( $(".ui-menu:visible").length, 0 );
132+
ac.autocomplete("destroy");
133+
start();
134+
}, 50);
135+
});
136+
119137
test("minLength", function() {
120138
var ac = $("#autocomplete").autocomplete({
121139
source: data

ui/jquery.ui.autocomplete.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ $.widget( "ui.autocomplete", {
3939
"aria-haspopup": "true"
4040
})
4141
.bind( "keydown.autocomplete", function( event ) {
42+
if ( self.options.disabled ) {
43+
return;
44+
}
45+
4246
var keyCode = $.ui.keyCode;
4347
switch( event.keyCode ) {
4448
case keyCode.PAGE_UP:
@@ -88,10 +92,18 @@ $.widget( "ui.autocomplete", {
8892
}
8993
})
9094
.bind( "focus.autocomplete", function() {
95+
if ( self.options.disabled ) {
96+
return;
97+
}
98+
9199
self.selectedItem = null;
92100
self.previous = self.element.val();
93101
})
94102
.bind( "blur.autocomplete", function( event ) {
103+
if ( self.options.disabled ) {
104+
return;
105+
}
106+
95107
clearTimeout( self.searching );
96108
// clicks on the menu (or a button to trigger a search) will cause a blur event
97109
self.closing = setTimeout(function() {

0 commit comments

Comments
 (0)