0

i'm using jquery ui autocomplete. 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

2 Answers 2

0

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

Sign up to request clarification or add additional context in comments.

Comments

0

I've found this solution:

https://github.com/scottgonzalez/jquery-ui-extensions/blob/master/autocomplete/jquery.ui.autocomplete.selectFirst.js

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.