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
To help a user make a selection in a long list, a dropdown typeahead shows suggestions as soon as the user starts typing.
Typeahead. A basic, easily extended plugin for quickly creating elegant typeaheads with any form text input.
What is Typeahead? Typeahead - also known as autocomplete or autosuggest - is a language prediction tool that many search interfaces use to provide suggestions for users as they type in a query.
Performs search to retrieve list of places by input text and location vicinity. Address Autocomplete takes free form text as input. It could be a part of an address. Location could be provided either as latitude/longitude or as country ISO code. It returns consolidated list of addresses based on the input text.
As of typeahead.js 0.10.5, this works :
$('#typeahead_object').typeahead('val', 'some value').blur()
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
You could manually trigger a keyup
event on the input element, after setting the value:
$("#typeahead_object").val('test').focus().trigger('keyup')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With