6

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();
   }
});
skurt
  • 1,019
  • 2
  • 13
  • 29

5 Answers5

6

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.

Ben Collins
  • 20,538
  • 18
  • 127
  • 187
5

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.

Community
  • 1
  • 1
Andrew Whitaker
  • 124,656
  • 32
  • 289
  • 307
3

As of jQuery UI v1.9 you can do something like the following:

$( "#q" ).autocomplete({
  source: "${createLink(mapping:'qsearch')}",
  select: function( event, ui ) {
    foo( ui.item.id );
  },
  search: function( event, ui ) {
    $( "#spinner" ).show();
  },
  response: function( event, ui ) {
    $( "#spinner" ).hide();
  }
});
jerrykan
  • 1,076
  • 9
  • 12
3

You can edit the CSS and remove the spinner.

$("object_that_has_the_spinner").removeClass( "ui-autocomplete-loading" );

specked
  • 519
  • 1
  • 6
  • 14
1

This is a known open enhancement for future versions of jQuery UI...

http://bugs.jqueryui.com/ticket/6777

Will have to wait and/or use a workaround (like sending a special response from the server and handle this case in the open event).

Nicolas Blanco
  • 11,164
  • 7
  • 38
  • 49