I'm trying to use Twitter typeahead.js to return a datum after selection. From what I understood by the documentation the code should look something like
$('.selector').typeahead({
name: 'identifier',
local: localObjectsArray
}).on('autocompleted', function(item){
alert(JSON.stringify(item));
});
However this doesn't work. What's the proper way to detect typeahead events?
typeahead({ itemSelected:function(data,value,text){ console. log(data) alert('value is'+value); alert('text is'+text); }, //your other stuffs }); You have to just pass itemSelected in the callback function and it will give you the selected item.
jQuery plugin that provides Typeahead (autocomplete) Search preview from Json object(s) via same domain Ajax request or cross domain Jsonp and offers data compression inside Local Storage. The plugin is built with a lot of options and callbacks to allow customization.
After selection, so you need typeahead:selected
:
$('.selector').typeahead({
name: 'identifier',
local: localObjectsArray
}).on('typeahead:selected', function (obj, datum) {
console.log(obj);
console.log(datum);
});
Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With