I got the following piece of code
$("#UserSearch").autocomplete({
source: "search.php",
minLength: 2
});
Here a user enters an email and I seek it through the database, but I need to find the moment when the autocomplete stops getting results. For example I got user@example.com and user2@example.com. If the current user seeks "user3" and the page no longer returns results how can I catch this moment so that I may display another element on the page.
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/
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');
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.