Reputation: 1445
I'm using jquery autocomplete and want it to focus a specific control once an item is selected from the autocomplete list. I tried $('#nextelement').focus()
, and it receives focus, but the focus goes back to the autocomplete control immediately. How can I retain focus to the next control when autocomplete closes?
[edit] I'm using autocomplete plugin that comes with Yii CAutoComplete widget, which the documentation states is this one: http://plugins.jquery.com/project/autocompletex
Upvotes: 0
Views: 1781
Reputation: 34178
This to me smells of a logic/use case of exactly when and what.
IF you select a value autocomplete that is valid you can check the change state of the control in focus of the autocomplete.
What if you do select one and how? (clicked, hit enter, just changed etc.)
I would think using the .change() event on the focused element would be best, then focus on the next element in your form - which depends on your construction of your page - sibling, next input, next by id, next sibling in the class, what to focus of this is the last element etc.
Upvotes: 0
Reputation: 413757
Have you tried:
setTimeout(function() {
$('#nextelement').focus();
}, 1);
to change the focus after the current event loop is done?
Upvotes: 2