Permalink
Browse files

add a "partial match" option.

  • Loading branch information...
1 parent 3868c23 commit eeb66b280c22e856b9484c657466852b6e79810c @aaronm67 aaronm67 committed Nov 13, 2012
Showing with 13 additions and 2 deletions.
  1. +1 −0 scripts/demo.js
  2. +12 −2 src/jquery.autocomplete.js
View
@@ -15,6 +15,7 @@ $(function () {
$('#query').autocomplete({
lookup: countries,
+ partialMatch: true,
onSelect: function (suggestion) {
status.html('You selected: ' + suggestion);
}
@@ -44,6 +44,7 @@
width: 0,
highlight: true,
params: {},
+ partialMatch: false,
fnFormatResult: fnFormatResult,
delimiter: null,
zIndex: 9999
@@ -263,7 +264,7 @@
},
getSuggestionsLocal: function (q) {
- var ret, arr, len, val, i, j, option, options;
+ var ret, arr, len, val, i, j, option, options, isMatch;
arr = this.options.lookup;
len = arr.suggestions.length;
ret = { suggestions: [], data: [] };
@@ -280,8 +281,17 @@
}
for (j = 0; j < options.length; j++) {
+ isMatch = false;
option = options[j];
- if (option.toLowerCase().indexOf(q) === 0) {
+
+ if (this.options.partialMatch === true && (option.toLowerCase().indexOf(q) >= 0)) {
+ isMatch = true;
+ }
+ else if (!this.options.partialMatch && (option.toLowerCase().indexOf(q) === 0)) {
+ isMatch = true;
+ }
+
+ if (isMatch) {
ret.suggestions.push(val);
ret.data.push(arr.data[i]);
break;

0 comments on commit eeb66b2

Please sign in to comment.