|
147 | 147 | suggestionSelector = '.' + that.classes.suggestion, |
148 | 148 | selected = that.classes.selected, |
149 | 149 | options = that.options, |
| 150 | + noSuggestionNotice = this.options.noSuggestionNotice, |
150 | 151 | container; |
151 | 152 |
|
152 | 153 | // Remove autocomplete attribute to prevent native suggestions: |
|
159 | 160 | } |
160 | 161 | }; |
161 | 162 |
|
| 163 | + // if notice is not string, it should be deep-copied, so every autocomplete instance has its own copy |
| 164 | + if(typeof noSuggestionNotice !== 'string') |
| 165 | + noSuggestionNotice = $(noSuggestionNotice).clone(true); |
162 | 166 | // html() deals with many types: htmlString or Element or Array or jQuery |
163 | 167 | that.noSuggestionsContainer = $('<div class="autocomplete-no-suggestion"></div>') |
164 | | - .html(this.options.noSuggestionNotice).get(0); |
| 168 | + .html(noSuggestionNotice).get(0); |
165 | 169 |
|
166 | 170 | that.suggestionsContainer = Autocomplete.utils.createNode(options.containerClass); |
167 | 171 |
|
|
208 | 212 |
|
209 | 213 | onFocus: function () { |
210 | 214 | var that = this; |
211 | | - that.fixPosition(); |
212 | 215 | if (that.options.minChars <= that.el.val().length) { |
213 | 216 | that.onValueChange(); |
214 | 217 | } |
|
634 | 637 |
|
635 | 638 | suggest: function () { |
636 | 639 | if (this.suggestions.length === 0) { |
637 | | - if (this.options.showNoSuggestionNotice) { |
| 640 | + |
| 641 | + var showNoSuggestionNotice = this.options.showNoSuggestionNotice; |
| 642 | + if(typeof this.options.showNoSuggestionNotice === 'function') |
| 643 | + showNoSuggestionNotice = this.options.showNoSuggestionNotice(this.suggestions); |
| 644 | + |
| 645 | + if(showNoSuggestionNotice) |
638 | 646 | this.noSuggestions(); |
639 | | - } else { |
| 647 | + else |
640 | 648 | this.hide(); |
641 | | - } |
642 | 649 | return; |
643 | 650 | } |
644 | 651 |
|
|
686 | 693 |
|
687 | 694 | this.adjustContainerWidth(); |
688 | 695 |
|
| 696 | + // Detach noSuggestions not to have it removed when filling container with new suggestions |
689 | 697 | noSuggestionsContainer.detach(); |
690 | 698 | container.html(html); |
691 | 699 |
|
| 700 | + // If showNoSuggestionNotice is a function, call it to see |
| 701 | + // if noSuggestionNotice should be added to theses suggestions |
| 702 | + if(typeof this.options.showNoSuggestionNotice === 'function' |
| 703 | + && this.options.showNoSuggestionNotice(that.suggestions)) { |
| 704 | + container.append(noSuggestionsContainer); |
| 705 | + } |
| 706 | + |
692 | 707 | if ($.isFunction(beforeRender)) { |
693 | 708 | beforeRender.call(that.element, container); |
694 | 709 | } |
|
0 commit comments