2
0
mirror of https://github.com/devbridge/jQuery-Autocomplete.git synced 2024-11-14 01:04:06 +00:00

Add lookupFilter function that can customized.

This commit is contained in:
Tomas Kirda 2013-01-15 11:53:05 -06:00
parent d7102f4001
commit 32857e7132
2 changed files with 13 additions and 7 deletions

View File

@ -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. * `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. * `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 }`. * `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 * `onSelect`: `function (suggestion) {}` Callback function invoked when user selects suggestion
from the list. `this` inside callback refers to input HtmlElement. from the list. `this` inside callback refers to input HtmlElement.
* `minChars`: Minimum number of characters required to trigger autosuggest. Default: `1`. * `minChars`: Minimum number of characters required to trigger autosuggest. Default: `1`.

View File

@ -86,7 +86,10 @@
noCache: false, noCache: false,
onSearchStart: noop, onSearchStart: noop,
onSearchComplete: noop, onSearchComplete: noop,
containerClass: 'autocomplete-suggestions' containerClass: 'autocomplete-suggestions',
lookupFilter: function (suggestion, originalQuery, queryLowerCase) {
return suggestion.value.toLowerCase().indexOf(queryLowerCase) !== -1;
}
}; };
// Shared variables: // Shared variables:
@ -351,12 +354,14 @@
return $.trim(parts[parts.length - 1]); return $.trim(parts[parts.length - 1]);
}, },
getSuggestionsLocal: function (q) { getSuggestionsLocal: function (query) {
q = q.toLowerCase(); var that = this,
queryLowerCase = query.toLowerCase(),
filter = that.options.lookupFilter;
return { return {
suggestions: $.grep(this.options.lookup, function (suggestion) { suggestions: $.grep(that.options.lookup, function (suggestion) {
return suggestion.value.toLowerCase().indexOf(q) !== -1; return filter(suggestion, query, queryLowerCase);
}) })
}; };
}, },