|
341 | 341 |
|
342 | 342 | // typeahead.js |
343 | 343 | if (self.options.typeaheadjs) { |
344 | | - var typeaheadConfig = null; |
345 | | - var typeaheadDatasets = {}; |
346 | 344 |
|
347 | | - // Determine if main configurations were passed or simply a dataset |
| 345 | + // Determine if main configurations were passed or simply a dataset |
348 | 346 | var typeaheadjs = self.options.typeaheadjs; |
349 | | - if ($.isArray(typeaheadjs)) { |
350 | | - typeaheadConfig = typeaheadjs[0]; |
351 | | - typeaheadDatasets = typeaheadjs[1]; |
352 | | - } else { |
353 | | - typeaheadDatasets = typeaheadjs; |
| 347 | + if (!$.isArray(typeaheadjs)) { |
| 348 | + typeaheadjs = array( null, typeaheadjs); |
354 | 349 | } |
| 350 | + var valueKey = typeaheadjs[1].valueKey; // We should test typeaheadjs.size >= 1 |
| 351 | + var f_datum = valueKey ? function (datum) { return datum[valueKey]; } |
| 352 | + : function (datum) { return datum; } |
| 353 | + $.fn.typeahead.apply(self.$input,typeaheadjs).on('typeahead:selected', $.proxy(function (obj, datum) { |
| 354 | + self.add( f_datum(datum) ); |
| 355 | + self.$input.typeahead('val', ''); |
| 356 | + }, self)); |
355 | 357 |
|
356 | | - self.$input.typeahead(typeaheadConfig, typeaheadDatasets).on('typeahead:selected', $.proxy(function (obj, datum) { |
357 | | - if (typeaheadDatasets.valueKey) |
358 | | - self.add(datum[typeaheadDatasets.valueKey]); |
359 | | - else |
360 | | - self.add(datum); |
361 | | - self.$input.typeahead('val', ''); |
362 | | - }, self)); |
363 | 358 | } |
364 | 359 |
|
365 | 360 | self.$container.on('click', $.proxy(function(event) { |
|
0 commit comments