Bootstrap typeahead - How to set the default value manually

shinchilla picture shinchilla · Aug 19, 2013 · Viewed 18.6k times · Source

I tried this:

$("#typeahead_object").val("test");

It only changes the textbox value but doesn't trigger the 'updater' function of the typeahead.

Question : How can I set the value of a typeahead object manually and trigger its updater function?

http://getbootstrap.com/2.3.2/javascript.html#typeahead

Answer

Andrew picture Andrew · Aug 31, 2014

To change typeahead input value, use the following construction:

$(input).typeahead('val',value);

So, in your case it should looks like:

$("#typeahead_object").typeahead('val',"test");

typeahead API documentation is available on https://github.com/twitter/typeahead.js/blob/master/doc/jquery_typeahead.md#datasets