Вопрос

How do I get typeahead to submit data.

Here is the relevant code on jsfiddle http://jsfiddle.net/6W3Qu/2/.

A copy of the 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 doesn't seem to enter the updater function

Это было полезно?

Решение

Typeahead.js doesn't have an "updater" option.

Instead you can write an event handler which will use typeahead's selected event (i.e. typeahead:selected) e.g.

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/

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top