Skip to content

Commit d2a12ff

Browse files
committed
Autocomplete: Abort pending ajax requests when disabled and prevent handling results when disabled. Fixes #6752 - Menu may still render when autocomplete is disabled.
1 parent ffc0855 commit d2a12ff

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

ui/jquery.ui.autocomplete.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ $.widget( "ui.autocomplete", {
229229
if ( key === "appendTo" ) {
230230
this.menu.element.appendTo( $( value || "body", this.element[0].ownerDocument )[0] )
231231
}
232+
if ( key === "disabled" && value && this.xhr ) {
233+
this.xhr.abort();
234+
}
232235
},
233236

234237
_initSource: function() {
@@ -243,7 +246,7 @@ $.widget( "ui.autocomplete", {
243246
} else if ( typeof this.options.source === "string" ) {
244247
url = this.options.source;
245248
this.source = function( request, response ) {
246-
if (self.xhr) {
249+
if ( self.xhr ) {
247250
self.xhr.abort();
248251
}
249252
self.xhr = $.ajax({
@@ -294,7 +297,7 @@ $.widget( "ui.autocomplete", {
294297
},
295298

296299
_response: function( content ) {
297-
if ( content && content.length ) {
300+
if ( !this.options.disabled && content && content.length ) {
298301
content = this._normalize( content );
299302
this._suggest( content );
300303
this._trigger( "open" );

0 commit comments

Comments
 (0)