How can I send data completed using autocompletion,

How do I get typeahead to send data.

Here is the corresponding jsfiddle code at http://jsfiddle.net/6W3Qu/2/ .

Copy of code:

var numbers = new Bloodhound({
datumTokenizer: function(d) { return Bloodhound.tokenizers.whitespace(d.num); },
queryTokenizer: Bloodhound.tokenizers.whitespace,
local: [
{ num: 'one' },
{ num: 'two' },
{ num: 'three' },
{ num: 'four' },
{ num: 'five' },
{ num: 'six' },
{ num: 'seven' },
{ num: 'eight' },
{ num: 'nine' },
{ num: 'ten' }
]
});

// initialize the bloodhound suggestion engine
numbers.initialize();

// instantiate the typeahead UI
$('.typeahead').typeahead(null, {
displayKey: 'num',
source: numbers.ttAdapter(),
updater: function(item) {
    alert(item);
}
});

It does not seem to be included in the update function

+3
source share
1 answer

Typeahead.js does not have the "updater" option.

Instead, you can write an event handler that will use the selected typeahead event (e.g. typeahead: selected), for example.

var numSelectedHandler = function (eventObject, suggestionObject, suggestionDataset) {
    alert(suggestionObject.num);
};

typeahead.on('typeahead:selected', numSelectedHandler);

A working example can be found here:

http://jsfiddle.net/Fresh/TXQdy/

+1
source

All Articles