Skip to content

Commit 08422d6

Browse files
committed
Autocomplete: Track pending requests and only remove the loading class when the last request completes. Fixes #6761 - Autocomplete: Loading class removed when multiple Ajax requests occur.
1 parent 0d0c862 commit 08422d6

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

ui/jquery.ui.autocomplete.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ $.widget( "ui.autocomplete", {
2626
},
2727
source: null
2828
},
29+
30+
pending: 0,
31+
2932
_create: function() {
3033
var self = this,
3134
doc = this.element[ 0 ].ownerDocument,
@@ -289,6 +292,7 @@ $.widget( "ui.autocomplete", {
289292
},
290293

291294
_search: function( value ) {
295+
this.pending++;
292296
this.element.addClass( "ui-autocomplete-loading" );
293297

294298
this.source( { term: value }, this.response );
@@ -302,7 +306,10 @@ $.widget( "ui.autocomplete", {
302306
} else {
303307
this.close();
304308
}
305-
this.element.removeClass( "ui-autocomplete-loading" );
309+
this.pending--;
310+
if ( !this.pending ) {
311+
this.element.removeClass( "ui-autocomplete-loading" );
312+
}
306313
},
307314

308315
close: function( event ) {

0 commit comments

Comments
 (0)