|
345 | 345 |
|
346 | 346 | // typeahead.js |
347 | 347 | 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 | + }); |
348 | 363 |
|
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); |
353 | 369 | } |
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)); |
361 | 370 |
|
| 371 | + self.$input.typeahead('val', ''); |
| 372 | + }, self)); |
362 | 373 | } |
363 | 374 |
|
364 | 375 | self.$container.on('click', $.proxy(function(event) { |
|
0 commit comments