9

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

Imane Fateh
  • 2,418
  • 3
  • 19
  • 23
shinchilla
  • 91
  • 1
  • 1
  • 3

3 Answers3

15

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

Andrew
  • 671
  • 2
  • 8
  • 21
2

You could manually trigger a keyup event on the input element, after setting the value:

$("#typeahead_object").val('test').focus().trigger('keyup')
kayen
  • 4,838
  • 3
  • 19
  • 20
1

As of typeahead.js 0.10.5, this works :

$('#typeahead_object').typeahead('val', 'some value').blur()

Jim
  • 1,062
  • 11
  • 24