I would like to be able to show a loading icon in the autocomplete dropdown while the searching is happening. How can I go about doing this?
Current code:
$("#searchbox").autocomplete({
search: function(event, ui) {
$('ul.ui-autocomplete').append("<li id='loading_icon'></li>");
$('ul.ui-autocomplete').show();
},
open: function(event, ui) {
$('#loading_icon').hide();
}
...
But what happens is the icon shows at the very top left of the browser page. The computing of the location hasn’t happened yet. Can i somehow make a call to compute the location of the autocomplete dropdown box?
Thanks!
This is doable, but you’ll have to convert your
sourceoption to a function and make the AJAX request yourself. For example:The last bit that overrides
_renderItemis doing so so that we can cancel the click event of the loading item (and prevent it from being placed in theinput).Example: http://jsfiddle.net/m3MGH/
Update, per comment below:
To show a loading image in a
div, you could do something like this (just changing the_renderItemfunction):You’ll probably have to use a little CSS to get things positioned just right, but this should get you started.