typeahead.js get selected datum

Sovos picture Sovos · Aug 2, 2013 · Viewed 19.3k times · Source

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?

Answer

Hieu Nguyen picture Hieu Nguyen · Aug 2, 2013

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.