Twitter Typeahead updater

TimH picture TimH · May 21, 2014 · Viewed 8.7k times · Source

Can anyone see what I have done wrong here? I have spent ages looking at a whole variety of typeahead code. Values are returned from the Json call that I can select, but I need to set the Id hidden field. I have tried all sorts in the updater function (log, alerts etc.) but zip. I believe its not triggering.

    var teamNames = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('Text'),
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    remote: 'List'
});

teamNames.initialize();

$('#remote #FullName').typeahead(null, {
    name: 'team-names',
    displayKey: 'Text',
    source: teamNames.ttAdapter(),
    updater: function(item){$('#Id').val(map[item].Value)}
})

Thanks a lot for any observations. If you think you have an answer please set as an answer so I can acknowledge - cheers.

Update - I suspect I have used some out of date or incompatible code. I have now used

 $('#FullName').bind('typeahead:selected', function (obj, datum, name) {}

that I found here on GitHub, thanks andy3rdworld, which works perfectly

Answer

Alex Zak picture Alex Zak · May 26, 2014

I had the same problem... I think we were relying on an example using an old version of typehead... /:

Typehead uses events now... Here's the example ended up following...