0

I'm using jQuery UI Autocomplete search and open events. But the open event is only called when the request is successful and there are elements. There does not seem to be an event when the response is successful but empty.

I display and hide a spinner logo when triggering the request, like this :

search: function() {
  $('.spinner').show();
},
open: function() {
  $('.spinner').hide();
}

This works well when there are elements in the server response but if the server response is empty the spinner stays forever...

Thanks for your answers.

PS : I'm not alone : remove spinner from jquery ui autocomplete if nothing found ;)

Community
  • 1
  • 1
Nicolas Blanco
  • 11,164
  • 7
  • 38
  • 49
  • perhaps better to add your comments there (that question) and START A BOUNTY! – Mark Schultheiss Mar 21 '11 at 14:47
  • possible duplicate of [remove spinner from jquery ui autocomplete if nothing found](http://stackoverflow.com/questions/4316071/remove-spinner-from-jquery-ui-autocomplete-if-nothing-found) – Mark Schultheiss Mar 21 '11 at 14:48
  • 1
    Please see my answers here (http://stackoverflow.com/questions/4316071/remove-spinner-from-jquery-ui-autocomplete-if-nothing-found/5391023#5391023) and here (http://stackoverflow.com/questions/4718968/detecting-no-results-on-jquery-ui-autocomplete/4719848#4719848) – Andrew Whitaker Mar 22 '11 at 12:16

3 Answers3

1

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

$('#field').autocomplete({
  source: source_url,
  search: function(event, ui) {
    $('#spinner').show();
  },
  response: function(event, ui) {
    $('#spinner').hide();
  }
});
jerrykan
  • 1,076
  • 9
  • 12
0

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
0

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