Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery ui autocomplete: count results

i would like to know if theres a way to count the number of results which are displayed when you type something in the textbox. Count the li-elements work, but i bet theres a smarter way. Thanks

like image 275
Johan Avatar asked Apr 04 '11 12:04

Johan


1 Answers

I don't think this is possible directly using JQueryUI Events. I've looked for a way without success.

All the events associated only return the element clicked (after the list is displayed), or information about the event (not about the list).

You can see it here: http://jqueryui.com/demos/autocomplete/#event-focus

What you said is the closest solution:

$( "#tags" ).autocomplete({
  source: availableTags,
  open: function(event,ui){
    var len = $('.ui-autocomplete > li').length;
    $('#count').html('Found '+len+' results');
  }
});
like image 78
Fran Verona Avatar answered Nov 16 '22 18:11

Fran Verona