|
83 | 83 | paramName: 'query', |
84 | 84 | transformResult: function (response) { |
85 | 85 | return typeof response === 'string' ? $.parseJSON(response) : response; |
86 | | - } |
| 86 | + }, |
| 87 | + showNoSuggestionNotice: false, |
| 88 | + noSuggestionNotice: 'No results' |
87 | 89 | }; |
88 | 90 |
|
89 | 91 | // Shared variables: |
|
544 | 546 |
|
545 | 547 | suggest: function () { |
546 | 548 | if (this.suggestions.length === 0) { |
547 | | - this.hide(); |
| 549 | + this.options.showNoSuggestionNotice ? this.noSuggestions() : this.hide(); |
548 | 550 | return; |
549 | 551 | } |
550 | 552 |
|
|
573 | 575 | html += '<div class="' + className + '" data-index="' + i + '">' + formatResult(suggestion, value) + '</div>'; |
574 | 576 | }); |
575 | 577 |
|
576 | | - // If width is auto, adjust width before displaying suggestions, |
577 | | - // because if instance was created before input had width, it will be zero. |
578 | | - // Also it adjusts if input width has changed. |
579 | | - // -2px to account for suggestions border. |
580 | | - if (options.width === 'auto') { |
581 | | - width = that.el.outerWidth() - 2; |
582 | | - container.width(width > 0 ? width : 300); |
583 | | - } |
| 578 | + this.adjustContainerWidth(); |
584 | 579 |
|
585 | 580 | container.html(html); |
586 | 581 |
|
|
600 | 595 | that.findBestHint(); |
601 | 596 | }, |
602 | 597 |
|
| 598 | + noSuggestions: function() { |
| 599 | + var that = this, |
| 600 | + container = $(that.suggestionsContainer), |
| 601 | + html = '', |
| 602 | + width; |
| 603 | + |
| 604 | + html += '<div class="autocomplete-no-suggestion">' + this.options.noSuggestionNotice + '</div>'; |
| 605 | + |
| 606 | + this.adjustContainerWidth(); |
| 607 | + container.html(html); |
| 608 | + container.show(); |
| 609 | + that.visible = true; |
| 610 | + }, |
| 611 | + |
| 612 | + adjustContainerWidth: function() { |
| 613 | + var that = this, |
| 614 | + options = that.options, |
| 615 | + width, |
| 616 | + container = $(that.suggestionsContainer) |
| 617 | + |
| 618 | + // If width is auto, adjust width before displaying suggestions, |
| 619 | + // because if instance was created before input had width, it will be zero. |
| 620 | + // Also it adjusts if input width has changed. |
| 621 | + // -2px to account for suggestions border. |
| 622 | + if (options.width === 'auto') { |
| 623 | + width = that.el.outerWidth() - 2; |
| 624 | + container.width(width > 0 ? width : 300); |
| 625 | + } |
| 626 | + }, |
| 627 | + |
603 | 628 | findBestHint: function () { |
604 | 629 | var that = this, |
605 | 630 | value = that.el.val().toLowerCase(), |
|
0 commit comments