-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unwanted behaviour when using $('.typeahead').typeahead('val', myVal); #646
Comments
I agree that this isn't ideal. I think the correct behavior should be dependent on whether the dropdown menu is open or closed. If it is closed, it should just update the input control. If it is opened, it should update the input control and request/render the corresponding suggestions. Does that sound reasonable? |
Yes, what you have proposed above sounds ideal. |
Linking to #402 as it's a similar issue. |
I found a workaround for this problem: var typeaheadInput= $('.typeahead').data('ttTypeahead').input;
typeaheadInput.setQuery(myVal);
typeaheadInput.resetInputValue(); |
Hi, another workaround that seems to work is to use jquery val although the docs advise otherwise (https://github.com/twitter/typeahead.js/blob/master/doc/jquery_typeahead.md#api) @jharding what's exactly the problem with this approach? Thanks. |
The typeahead jQuery plugin cannot detect when you manually set the value of the input, so there's a chance some internal state can get out of sync when you do this. I should actually verify this though as quite a bit has changed since I initially recommended that. |
Hello – I can confirm the state gets out of sync when using |
I am unsure how this behavior was resolved. I just installed this component and used Right now, I resolve this using
|
Also, even if the suggestion list is closed, I find that setting some items cause the autocomplete to show a hint when it's not supposed to. For example : el.typeahead('val', 'foo'); Will set the correct value How do I set a value without triggering a search, suggesitons, and autocomplete? |
Well, instead of using
|
Also the documentation could be less ambiguous, it is not clear it the typeahead ("val",val) will only set the value or trigger the search too. |
Whilst answering a StackOverflow question I found what I deem to be undesirable behaviour with the "$('.typeahead').typeahead('val', myVal);" function.
When this function is called it causes "myVal" to be correctly inserted, however it causes the suggestion box to also appear. I think users will expect this function to just populate the typeahead control (i.e. just like a call to $('.typeahead').val(myVal);)).
See this jsFiddle and uncomment the call to typeahead('val', ...) to recreate the issue.
Is this indeed an issue or is it expected behaviour?
The text was updated successfully, but these errors were encountered: