You can consider to check the number of displayed elements in the open
event, if the len
is 0 you can display another element accordingly.
Other solutions are to use a custom _renderItem
function or a custom extended widget, but in this case this can be a simpler solution.
Code:
$("#project").autocomplete({
minLength: 0,
source: projects,
open: function (event, ui) {
var len = $('.ui-autocomplete > li').length;
$('#count').html('Founded ' + len + ' results');
}
});
Demo: http://jsfiddle.net/IrvinDominin/DZ9zU/
UPDATE
Better using response
event:
Triggered after a search completes, before the menu is shown. Useful for local manipulation of suggestion data, where a custom source option callback is not required. This event is always triggered when a search completes, even if the menu will not be shown because there are no results or the Autocomplete is disabled.
Code:
$("#project").autocomplete({
minLength: 0,
source: projects,
response: function (event, ui) {
var len = ui.content.length;
$('#count').html('Founded ' + len + ' results');
}
});