user3421619
user3421619

Reputation: 21

Adding a default value for the suggestions in typeahead

I wanted to add a default value (All) in the dropdown list of typeahead apart from the suggested value that comes up in the dropdown list when the user types some text in the typeahead textfield.

Any help on this is greatly appreciated.

Thanks

Upvotes: 2

Views: 2679

Answers (1)

bmc
bmc

Reputation: 626

If you're using the latest version of typeahead.js for Bootstrap 3, then you can add another dataset that always returns the default value you want:

$('input').typeahead(null,
    //real dataset
    {
        name: 'real-data',
        source: backend.ttAdapter() //Your current suggestions
    },

    //default dataset - will always be shown in dropdown
    {
        name: 'default-data',
        source: function(query, callback) {
            callback([{value: 'All'}]);
        }
    }
);

See this section of the docs for more information.

Upvotes: 1

Related Questions