Skip to content

Commit 41fe4aa

Browse files
committed
Merge branch 'SylvainCorlay-multi_typeahead'
2 parents 0d5531c + d456e35 commit 41fe4aa

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

src/bootstrap-tagsinput.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -345,20 +345,31 @@
345345

346346
// typeahead.js
347347
if (self.options.typeaheadjs) {
348+
// Determine if main configurations were passed or simply a dataset
349+
var typeaheadjs = self.options.typeaheadjs;
350+
if (!$.isArray(typeaheadjs)) {
351+
typeaheadjs = [null, typeaheadjs];
352+
}
353+
354+
$.fn.typeahead.apply(self.$input, typeaheadjs).on('typeahead:selected', $.proxy(function (obj, datum, name) {
355+
var index = 0;
356+
typeaheadjs.some(function(dataset, _index) {
357+
if (dataset.name === name) {
358+
index = _index;
359+
return true;
360+
}
361+
return false;
362+
});
348363

349-
// Determine if main configurations were passed or simply a dataset
350-
var typeaheadjs = self.options.typeaheadjs;
351-
if (!$.isArray(typeaheadjs)) {
352-
typeaheadjs = [null, typeaheadjs];
364+
// @TODO Dep: https://github.com/corejavascript/typeahead.js/issues/89
365+
if (typeaheadjs[index].valueKey) {
366+
self.add(datum[typeaheadjs[index].valueKey]);
367+
} else {
368+
self.add(datum);
353369
}
354-
var valueKey = typeaheadjs[1].valueKey; // We should test typeaheadjs.size >= 1
355-
var f_datum = valueKey ? function (datum) { return datum[valueKey]; }
356-
: function (datum) { return datum; }
357-
$.fn.typeahead.apply(self.$input,typeaheadjs).on('typeahead:selected', $.proxy(function (obj, datum) {
358-
self.add( f_datum(datum) );
359-
self.$input.typeahead('val', '');
360-
}, self));
361370

371+
self.$input.typeahead('val', '');
372+
}, self));
362373
}
363374

364375
self.$container.on('click', $.proxy(function(event) {

0 commit comments

Comments
 (0)