Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap Typeahead: Remove forced selection of first item

Hi I am using typeahead in twitter bootstrap. What I found here is that in autocomplete dropdown, it selects first option by default. My requirement is that initially it should have nothing selected, it goes to first option only when I press navigation key (up or down) or when I hover over it. Is it possibe using typeahead.

like image 994
Paritosh Singh Avatar asked Dec 26 '12 00:12

Paritosh Singh


2 Answers

To avoid selection by typeahead first option by default, I used parameter documented in official docs: autoSelect. By default it set to 'true'

My code:

$('#searchString', this.el).typeahead({
        source: function (query, process) {
            var q = '/autocompleteSearch?searchString=' + query;               

            return $.get(q, function (data) {
                return process(data);
            });
        },
        minLength: 3,
        autoSelect: false
    });
like image 94
Artem Zaika Avatar answered Oct 19 '22 13:10

Artem Zaika


There is the more powerfull typeahead project from Twitter which doesn't have this problem. I don't understand why this project is not included directly in Twitter Bootstrap.

You can see here some examples.

like image 2
Sonson123 Avatar answered Oct 19 '22 12:10

Sonson123