Reputation: 83
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
Upvotes: 3
Views: 9253
Reputation: 366
Bloodhound Suport Type Head like this
var numSelectedHandler = function(eventObject, suggestionObject, suggestionDataset) {
$('#postal_code').typeahead('val', suggestionObject.key);
};
$('#postal_code').on('typeahead:selected', numSelectedHandler);
Upvotes: 1
Reputation: 2174
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...
Upvotes: 6