Shawn Collier
Shawn Collier

Reputation: 149

Keep focus on input when tab-selecting a jQuery autocomplete entry

http://jqueryui.com/demos/autocomplete/

Basically my issue is that when the user uses the tab key to select an item, the next form field gets the focus, but unless the input is empty, I want the focus to stay on the input.

$('.ui-autocomplete').keypress(function(event) {
    if(event.keyCode == '9') { // Tab
        console.log('test');
    }
});

I thought the above code might work (or doing the function on the actual li items generated by jQuery UI), but no dice.

Any ideas? I know I'm close but I just can't figure out what element I need to tie this to.

Upvotes: 0

Views: 1759

Answers (1)

Shawn Collier
Shawn Collier

Reputation: 149

Figured out that I needed to use the same code I used before on the input, but use "keydown" instead of "keypress".

Upvotes: 1

Related Questions