-
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
Input value blank on blur #28
Comments
Labeled this as a low-hanging fruit. It should be a very easy fix, basically all you have to do is change the following in the InputView constructor from: this.query = ''; to: this.query = this.$input.val(); If anyone out there wants to submit a pull request for this, go for it (be sure to include tests!). Otherwise I'll get to it when I can. |
You're right – the fix I suggested would work if you set the value of the input before initializing the typeahead, which is only a part of the issue. The other part is dynamically setting the value after initialization. I think for that a plugin method will have to be added. |
I'll get to it if I can. |
@jharding This fixes the second part of the issue. When you call click() event - the value in box has already set so this solution will keep the value in the box otherwise use the one from query _setInputValueToQuery: function() {
this.inputView.setInputValue(this.inputView.$input.val() || this.inputView.getQuery());
}, |
@orald unfortunately that's not a complete solution, at least in my opinion. The reason I say that is because if you were to run: $('.typeahead').val('new query'); I would expect suggestions to be rendered for Since there's not a great way of reliably and efficiently detecting programmatic changes to a value of an input (at least I'm not aware of anything), I think the only way we can really tackle this is by add a $('.typeahead').typeahead({ /* ... */ }).typeahead('setQuery', 'new query'); |
@jharding Yes you are right. No easy way to detect changes to a value of input. As you suggested the following works as expected. methods= {
...
setQuery: function(value){
var $this = $(this),
view = $this.data('typeahead'),
iv = view.inputView;
iv.setInputValue(value);
}
} I also added the dropdownhide function call on queryChange listener $('.typeahead').typeahead('setQuery', 'new query'); twice or more. It renders on top of previous one. |
folks not sure if this is the right place to ask this question, how do you implement this? when/where do you call $('.typeahead').typeahead('setQuery', 'new query');? |
The API has changed, you now would want to use |
I'm curious how to implement this as well. When I autofill a typeahead enabled field, if a user clicks on that field, I don't want the value to disappear. |
I don't really get how it should be working? remote: {
wildcard: '%QUERY',
url: '/api/search?q=%QUERY',
} Now, when I see the results. I can navigate threw them using up/down. Thank you |
can someone give a simple example of what do to to prevent the field from getting emptied by a blur event? |
@HamsterofDeath not me ;( |
i found a working hack
|
To avoid the blur field reset problem, I changed the plugin code (v. 0.11.1) at row 1487: to: var val = (this.query && this.query.length > 0) ? this.query : this.getInputValue(); I hope this will help someone! :-) |
@HamsterofDeath thanks! Your answer was a huge help to me and worked like a charm on my older 0.10.5 version of typeahead (did not want to adjust the CSS to upgrade to the latest). I just did the following after initializing the typeahead:
|
always happy to help
Gesendet: Freitag, 30. Juni 2023 um 18:43 Uhr
Von: "ryandaugherty7" ***@***.***>
An: "twitter/typeahead.js" ***@***.***>
Cc: "HamsterofDeath" ***@***.***>, "Mention" ***@***.***>
Betreff: Re: [twitter/typeahead.js] Input value blank on blur (#28)
@HamsterofDeath thanks! Your answer was a huge help to me and worked like a charm on my older 0.10.5 version of typeahead (did not want to adjust the CSS to upgrade to the latest). I just did the following after initializing the typeahead:
$('#search-query').unbind("blur");
$('#search-query').on("blur", function(evt) {$('#search-query').typeahead("close")});
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Go to the example demo page,
$('input[placeholder="countries"]').val('France').click().blur(); the input value is now blank.
If you set a value, you would like to keep it no ? (I would)
Same problem if the input contains a value before becoming a typeahead input.
The text was updated successfully, but these errors were encountered: