mirror of
https://github.com/devbridge/jQuery-Autocomplete.git
synced 2024-11-09 23:01:00 +00:00
Add lookupFilter function that can customized.
This commit is contained in:
parent
d7102f4001
commit
32857e7132
@ -15,6 +15,7 @@ The standard jquery.autocomplete.js file is around 2.7KB when minified via Closu
|
||||
* `serviceUrl`: Server side URL that provides results for suggestions. Optional if local lookup data is provided.
|
||||
* `lookup`: Lookup array for the suggestions. It may be array of strings or `suggestion` object literals.
|
||||
* `suggestion`: An object literal with the following format: `{ value: 'string', data: any }`.
|
||||
* `lookupFilter`: `function (suggestion, query, queryLowerCase) {}` filter function for local lookups. By default it does partial string match (case insensitive).
|
||||
* `onSelect`: `function (suggestion) {}` Callback function invoked when user selects suggestion
|
||||
from the list. `this` inside callback refers to input HtmlElement.
|
||||
* `minChars`: Minimum number of characters required to trigger autosuggest. Default: `1`.
|
||||
|
@ -86,7 +86,10 @@
|
||||
noCache: false,
|
||||
onSearchStart: noop,
|
||||
onSearchComplete: noop,
|
||||
containerClass: 'autocomplete-suggestions'
|
||||
containerClass: 'autocomplete-suggestions',
|
||||
lookupFilter: function (suggestion, originalQuery, queryLowerCase) {
|
||||
return suggestion.value.toLowerCase().indexOf(queryLowerCase) !== -1;
|
||||
}
|
||||
};
|
||||
|
||||
// Shared variables:
|
||||
@ -249,7 +252,7 @@
|
||||
|
||||
onKeyPress: function (e) {
|
||||
var that = this;
|
||||
|
||||
|
||||
// If suggestions are hidden and user presses arrow down, display suggestions:
|
||||
if (!that.disabled && !that.visible && e.keyCode === keys.DOWN && that.currentValue) {
|
||||
that.suggest();
|
||||
@ -351,12 +354,14 @@
|
||||
return $.trim(parts[parts.length - 1]);
|
||||
},
|
||||
|
||||
getSuggestionsLocal: function (q) {
|
||||
q = q.toLowerCase();
|
||||
getSuggestionsLocal: function (query) {
|
||||
var that = this,
|
||||
queryLowerCase = query.toLowerCase(),
|
||||
filter = that.options.lookupFilter;
|
||||
|
||||
return {
|
||||
suggestions: $.grep(this.options.lookup, function (suggestion) {
|
||||
return suggestion.value.toLowerCase().indexOf(q) !== -1;
|
||||
suggestions: $.grep(that.options.lookup, function (suggestion) {
|
||||
return filter(suggestion, query, queryLowerCase);
|
||||
})
|
||||
};
|
||||
},
|
||||
@ -499,7 +504,7 @@
|
||||
|
||||
moveUp: function () {
|
||||
var that = this;
|
||||
|
||||
|
||||
if (that.selectedIndex === -1) {
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user