Example of typeahead:selected event
See original GitHub issueFor anyone interested until an example is added to documentation for custom events…
Assuming there’s an input on your page called ‘search_input’:
$('#search_input').bind('typeahead:selected', function(obj, datum, name) {
alert(JSON.stringify(obj)); // object
// outputs, e.g., {"type":"typeahead:selected","timeStamp":1371822938628,"jQuery19105037956037711017":true,"isTrigger":true,"namespace":"","namespace_re":null,"target":{"jQuery19105037956037711017":46},"delegateTarget":{"jQuery19105037956037711017":46},"currentTarget":
alert(JSON.stringify(datum)); // contains datum value, tokens and custom fields
// outputs, e.g., {"redirect_url":"http://localhost/test/topic/test_topic","image_url":"http://localhost/test/upload/images/t_FWnYhhqd.jpg","description":"A test description","value":"A test value","tokens":["A","test","value"]}
// in this case I created custom fields called 'redirect_url', 'image_url', 'description'
alert(JSON.stringify(name)); // contains dataset name
// outputs, e.g., "my_dataset"
});
Issue Analytics
- State:
- Created 10 years ago
- Reactions:17
- Comments:41 (3 by maintainers)
Top Results From Across the Web
Handle selected event in autocomplete textbox using ...
I want to run JavaScript function just after user select a value using autocomplete textbox bootstrap Typeahead. I'm ...
Read more >Using Twitter Typeahead.js Custom Event Triggers | Blog
typeahead:selected – Triggered when a suggestion from the dropdown menu is explicitly selected. The datum for the selected suggestion is passed to the...
Read more >Twitter Typeahead custom event demo - CodePen
Simple demo for a [Stack Overflow Answer](http://stackoverflow.com/questions/18710325/twitter-bootstrap-typeahead-custom-keypress-enter-function/187108...
Read more >typeahead.js – examples - Twitter Open Source
When initializing a typeahead using the typeahead.js jQuery plugin, you pass the plugin method one or more datasets. The source of a dataset...
Read more >jQuery | Autocomplete Selection Event - GeeksforGeeks
The very basic purpose of this feature is to replace the value of the text field with the selected value from the list...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I was banging my head against the wall so… please note that now the event is “typeahead:select” and NO LONGER “selected”… after this, the original example still works and is the correct way to do it, thanks!
@maanasa Give this a shot? Looks like you were binding to the input field itself rather than the typeahead object.