Select first if return key is pressed and there isn't item selected with jquery ui autocomplete
i'm using jquery ui autoco开发者_运维技巧mplete. I want that when there isn't items selected and user press return key, the first element of the results is selected automatically.
is possible do it?
How can i do?
thanks
Use the change event, and test whether there was an item selected.
,change: function(event,ui) {
// the user has tabbed away without choosing anything from the list
// console.log(ui.item);
if( ui.item == null ) {
console.log("no item selected")
}
}
here's that event in documentation for jQueryUI 1.8.6 http://jqueryui.com/demos/autocomplete/#event-change
and here's another stackoverflow question with a much more complicated solution, along the same lines: Jquery UI autocomplete event change
I've found this solution:
https://github.com/scottgonzalez/jquery-ui-extensions/blob/master/autocomplete/jquery.ui.autocomplete.selectFirst.js
精彩评论