Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove spinner from jquery ui autocomplete if nothing found

I want to remove the spinner (picture which shows that it is loading) from the textfield which supports jquery ui autocomplete. As there is no event for "no results returned by source" a can not trigger this.

$( "#q" ).autocomplete({
   source: "${createLink(mapping:'qsearch')}",
   minLength: 2,
   select: function( event, ui ) {
      foo( ui.item.id );
   },
   search: function( event, ui ) {
      bla();
   }
});
like image 601
skurt Avatar asked Nov 30 '10 16:11

skurt


2 Answers

If you're stuck on an older version of jQuery ui, the right answer is to use the class ui-autocomplete-loading, which gets added and removed while the request/response is in flight.

like image 96
Ben Collins Avatar answered Nov 15 '22 08:11

Ben Collins


Adapted from my answer here, add the following code to execute after a search is complete (even with 0 results):

var __response = $.ui.autocomplete.prototype._response;
$.ui.autocomplete.prototype._response = function(content) {
    __response.apply(this, [content]);
    this.element.trigger("autocompletesearchcomplete", [content]);
};

That code will trigger an event (autocompletesearchcomplete) that you can then bind to:

$("#q").bind("autocompletesearchcomplete", function(event, contents) {
    /* Remove spinner here */
});

Hope that helps.

like image 42
Andrew Whitaker Avatar answered Nov 15 '22 10:11

Andrew Whitaker