Charles
Charles

Reputation: 11

how to make jquery autocomplete select an item when press up and down

when I use jquery autocomplete, everytime I type something , first item of the list is automatically selected . For instance , if the list if [ ajax , asp , autocomplete ] , when I type 'a' , these three will show up and the first item is highlighted . Is a way that no item is highlighted until I press up or down .

Upvotes: 1

Views: 825

Answers (2)

kobe
kobe

Reputation: 15835

You need to implement Keyup and Keydown events

I gave you code from my project , please see if it useful

switch (key) {
            case KEYUP:
                if (me.highlighted > 0) {
                    me.highlighted--;
                }
                else {
                    $('#txtSearch').val(userSearchTerm);
                    me.highlighted = -1;
                }
                if ($('.searchSuggest').css('display') != 'none') {
                    me.changeHighlight(key);
                }
                break;

            case KEYDN:
                if (me.highlighted < $('.ssg_results .ssgItem').length - 1) {
                    me.highlighted++;
                }
                if ($('.searchSuggest').css('display') != 'none') {
                    me.changeHighlight(key);
                }
                break;
        }

Upvotes: 1

duncan
duncan

Reputation: 31912

Try adding this to the options:

highlight: false

Alternatively, you might want to try this instead or even additionally:

selectFirst: false

Upvotes: 1

Related Questions