Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
added "transformQuery" to options
The function "transformQuery" lets one do some operations on the query before it's analyzed by the script; the default is to do nothing and pass the query unchanged. Useful for example to "slugify" the query so that "métro" becomes "metro" for example. (slugify: cf. underscore-string)
  • Loading branch information
bambax committed Apr 1, 2014
commit 30ffdfba0dbe88fc08b58c62d941ffaf17cbc445
8 changes: 6 additions & 2 deletions src/jquery.autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
lookupFilter: function (suggestion, originalQuery, queryLowerCase) {
return suggestion.value.toLowerCase().indexOf(queryLowerCase) !== -1;
},
transformQuery: function(query) {
return query;
},
paramName: 'query',
transformResult: function (response) {
return typeof response === 'string' ? $.parseJSON(response) : response;
Expand Down Expand Up @@ -439,12 +442,13 @@

getQuery: function (value) {
var delimiter = this.options.delimiter,
tvalue = this.options.transformQuery(value),
parts;

if (!delimiter) {
return value;
return tvalue;
}
parts = value.split(delimiter);
parts = tvalue.split(delimiter);
return $.trim(parts[parts.length - 1]);
},

Expand Down