Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ $(selector).autocomplete(options);
| `noSuggestionNotice` | `No results` | Text or htmlString or Element or jQuery object for no matching results label |
| `onInvalidateSelection` | optional | `function () {}` called when input is altered after selection has been made. `this` is bound to input element |
| `tabDisabled` | `false` | Set to true to leave the cursor in the input field after the user tabs to select a suggestion |
| `hideInvalidSuggestions` | `false` | Set to true to hide suggestions which do not contain the query |


### Event function settings (local and Ajax)
Expand Down
28 changes: 21 additions & 7 deletions src/jquery.autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@
showNoSuggestionNotice: false,
noSuggestionNotice: 'No results',
orientation: 'bottom',
forceFixPosition: false
forceFixPosition: false,
hideInvalidSuggestions: false
};

function _lookupFilter(suggestion, originalQuery, queryLowerCase) {
Expand Down Expand Up @@ -265,7 +266,7 @@
'z-index': options.zIndex
});

this.options = options;
this.options = options;
},


Expand Down Expand Up @@ -622,11 +623,7 @@

suggest: function () {
if (!this.suggestions.length) {
if (this.options.showNoSuggestionNotice) {
this.noSuggestions();
} else {
this.hide();
}
this.noSuggestionsAvailable();
return;
}

Expand Down Expand Up @@ -661,13 +658,22 @@

// Build suggestions inner HTML:
$.each(that.suggestions, function (i, suggestion) {
if (that.options.hideInvalidSuggestions && suggestion.value.toLowerCase().indexOf(value.toLowerCase()) === -1) {
return true; // continue;
}

if (groupBy){
html += formatGroup(suggestion, value, i);
}

html += '<div class="' + className + '" data-index="' + i + '">' + formatResult(suggestion, value, i) + '</div>';
});

if (html === '') { // No matching suggestions, hide container
this.noSuggestionsAvailable();
return;
}

this.adjustContainerWidth();

noSuggestionsContainer.detach();
Expand All @@ -691,6 +697,14 @@
that.findBestHint();
},

noSuggestionsAvailable: function () {
if (this.options.showNoSuggestionNotice) {
this.noSuggestions();
} else {
this.hide();
}
},

noSuggestions: function() {
var that = this,
beforeRender = that.options.beforeRender,
Expand Down