By using jqueryUi
autocomplete
I would like the first item automatically focused only when the user type on tab key
.
How should I perform this task?
Initialising a autocomplete with the autoFocus
option
true
specified does not fit my purpose!
Any ideas?
Here is my code.
Please see the comment for more details.
element.autocomplete({
minLength: 3,
// the following option "autoFocus = true"
// make the first item focused when the user type the first 3 letters
// I would like the first item focused only when I type on TAB
autoFocus: false,
source: function (request, response) {
// some code
}
}).data('autocomplete')._renderItem = renderItem;
// the following piece of code works only when I type the first three letters,
// If I type four letters and then tab it does not work!
element.on('keyup', function (event) {
if (event.keyCode === 9) {
element.autocomplete( "option", "autoFocus", true );
}
});