|
58 | 58 | serviceUrl: null, |
59 | 59 | lookup: null, |
60 | 60 | keyPath: "suggestions", |
| 61 | + valueKey: "value", |
61 | 62 | onSelect: null, |
62 | 63 | width: 'auto', |
63 | 64 | minChars: 1, |
|
118 | 119 |
|
119 | 120 | $.Autocomplete = Autocomplete; |
120 | 121 |
|
121 | | - Autocomplete.formatResult = function (suggestion, currentValue) { |
| 122 | + Autocomplete.formatResult = function (suggestion, currentValue, context) { |
122 | 123 | var pattern = '(' + utils.escapeRegExChars(currentValue) + ')'; |
123 | 124 |
|
124 | | - return suggestion.value.replace(new RegExp(pattern, 'gi'), '<strong>$1<\/strong>'); |
| 125 | + return suggestion[context.options.valueKey].replace(new RegExp(pattern, 'gi'), '<strong>$1<\/strong>'); |
125 | 126 | }; |
126 | 127 |
|
127 | 128 | Autocomplete.prototype = { |
|
429 | 430 | queryLowerCase = query.toLowerCase(); |
430 | 431 |
|
431 | 432 | $.each(that.suggestions, function (i, suggestion) { |
432 | | - if (suggestion.value.toLowerCase() === queryLowerCase) { |
| 433 | + if (suggestion[that.options.valueKey].toLowerCase() === queryLowerCase) { |
433 | 434 | index = i; |
434 | 435 | return false; |
435 | 436 | } |
|
571 | 572 |
|
572 | 573 | // Build suggestions inner HTML: |
573 | 574 | $.each(that.suggestions, function (i, suggestion) { |
574 | | - html += '<div class="' + className + '" data-index="' + i + '">' + formatResult(suggestion, value) + '</div>'; |
| 575 | + html += '<div class="' + className + '" data-index="' + i + '">' + formatResult(suggestion, value, that) + '</div>'; |
575 | 576 | }); |
576 | 577 |
|
577 | 578 | // If width is auto, adjust width before displaying suggestions, |
|
611 | 612 | } |
612 | 613 |
|
613 | 614 | $.each(that.suggestions, function (i, suggestion) { |
614 | | - var foundMatch = suggestion.value.toLowerCase().indexOf(value) === 0; |
| 615 | + var foundMatch = suggestion[that.options.valueKey].toLowerCase().indexOf(value) === 0; |
615 | 616 | if (foundMatch) { |
616 | 617 | bestMatch = suggestion; |
617 | 618 | } |
|
625 | 626 | var hintValue = '', |
626 | 627 | that = this; |
627 | 628 | if (suggestion) { |
628 | | - hintValue = that.currentValue + suggestion.value.substr(that.currentValue.length); |
| 629 | + hintValue = that.currentValue + suggestion[that.options.valueKey].substr(that.currentValue.length); |
629 | 630 | } |
630 | 631 | if (that.hintValue !== hintValue) { |
631 | 632 | that.hintValue = hintValue; |
|
751 | 752 | $(that.suggestionsContainer).scrollTop(offsetTop - that.options.maxHeight + heightDelta); |
752 | 753 | } |
753 | 754 |
|
754 | | - that.el.val(that.getValue(that.suggestions[index].value)); |
| 755 | + that.el.val(that.getValue(that.suggestions[index].this[valueKey])); |
755 | 756 | that.signalHint(null); |
756 | 757 | }, |
757 | 758 |
|
|
760 | 761 | onSelectCallback = that.options.onSelect, |
761 | 762 | suggestion = that.suggestions[index]; |
762 | 763 |
|
763 | | - that.currentValue = that.getValue(suggestion.value); |
| 764 | + that.currentValue = that.getValue(suggestion[that.valueKey]); |
764 | 765 | that.el.val(that.currentValue); |
765 | 766 | that.signalHint(null); |
766 | 767 | that.suggestions = []; |
|
0 commit comments