-
-
Notifications
You must be signed in to change notification settings - Fork 78.5k
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
typeahead: add "selected" custom event #3102
Comments
|
No. "change" is an event when something has changed in input box. But I need to distinguish cases when something is being entered in input and was chosen from dropdown menu. p.s. please let me know if I couldn't describe my idea well |
no - change is being manually triggered: this.$element.change() |
right - change is being triggered in select method manually but is also triggered by input itself. And in my callback subscribed on the event I can't see difference between "change" from "select" method and "change" from DOM/jQuery. |
i think you should listen to blur for your case above |
How can blur help? In blur-handler I can get value from input but I can't be sure that it's was chosen from the list.
In the latter case we need a separated event for selecting a value from the list. |
Blur could help - if you're waiting for a user to complete what they intend on inputing. But if you're really set on adding this event i'm open to it. You'll want to reopen a pull request against 2.0.3-wip though - and add preventDefault support (like this: https://github.com/twitter/bootstrap/blob/2.0.3-wip/js/bootstrap-modal.js#L45) You'll also need a test and docs. thanks! |
Here's the pull request: #3158 (tests and docs are included). |
To make custom events for typeahead you can use my thing: https://github.com/finom/Functions/tree/master/FunctionCallEvent#why-is-it-needed |
The "selected" event would be useful in some cases. It often makes a difference, wether the user did select input from the typeahead list, or manually wrote some random input. But the "change" even fires in both cases. A simple/hack way to tell the difference using the "change" event would be: $(".typeahead").on("change", function (e) {
if (!e.originalEvent) {
// the change event was manually triggered
}
}) |
I need to handle a case when a user selects an options from dropdown menu. I need to distinguish entered text and chosen from dropdown menu. It's imposible without the custom event.
The text was updated successfully, but these errors were encountered: