typeahead.js icon indicating copy to clipboard operation
typeahead.js copied to clipboard

How to set value to an input field (programmatically) bound by typeahead

Open rvnath opened this issue 12 years ago • 3 comments

In my app, I bound an input field to the typeahead. After ths I am unable to set value to the input field using the .val() method. It doesn't seem to work.

Even when I set the value to the hidden input.tt-hint and span classes, still it doesn't work.

It works only when I manually type something into the input.

Can someone help me on this...

rvnath avatar Dec 27 '13 13:12 rvnath

You should use the setQuery method of typeahead for this. In case you are using the prefetched option, you should do this on the typeahead:initialized event. For example $('#yourBoxId').typeahead('setQuery','yourValue')

Svakinn avatar Dec 27 '13 13:12 Svakinn

Thax Svakinn. It works perfect!

rvnath avatar Dec 27 '13 16:12 rvnath

Not in this version but in this case the JQuery val() functon works perfectly. var currentValue = $('#yourBoxId').val();

Svakinn avatar Dec 27 '13 16:12 Svakinn