Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add a "partial match" option.

  • Loading branch information...
commit eeb66b280c22e856b9484c657466852b6e79810c 1 parent 3868c23
Aaron Marasco authored November 13, 2012
1  scripts/demo.js
@@ -15,6 +15,7 @@ $(function () {
15 15
 
16 16
         $('#query').autocomplete({
17 17
             lookup: countries,
  18
+            partialMatch: true,
18 19
             onSelect: function (suggestion) {
19 20
                 status.html('You selected: ' + suggestion);
20 21
             }
14  src/jquery.autocomplete.js
@@ -44,6 +44,7 @@
44 44
             width: 0,
45 45
             highlight: true,
46 46
             params: {},
  47
+            partialMatch: false,
47 48
             fnFormatResult: fnFormatResult,
48 49
             delimiter: null,
49 50
             zIndex: 9999
@@ -263,7 +264,7 @@
263 264
         },
264 265
 
265 266
         getSuggestionsLocal: function (q) {
266  
-            var ret, arr, len, val, i, j, option, options;
  267
+            var ret, arr, len, val, i, j, option, options, isMatch;
267 268
             arr = this.options.lookup;
268 269
             len = arr.suggestions.length;
269 270
             ret = { suggestions: [], data: [] };
@@ -280,8 +281,17 @@
280 281
                 }
281 282
 
282 283
                 for (j = 0; j < options.length; j++) {
  284
+                    isMatch = false;
283 285
                     option = options[j];
284  
-                    if (option.toLowerCase().indexOf(q) === 0) {
  286
+
  287
+                    if (this.options.partialMatch === true && (option.toLowerCase().indexOf(q) >= 0)) {
  288
+                        isMatch = true;
  289
+                    }
  290
+                    else if (!this.options.partialMatch && (option.toLowerCase().indexOf(q) === 0)) {
  291
+                        isMatch = true;
  292
+                    }
  293
+
  294
+                    if (isMatch) {
285 295
                         ret.suggestions.push(val);
286 296
                         ret.data.push(arr.data[i]);
287 297
                         break;

0 notes on commit eeb66b2

Please sign in to comment.
Something went wrong with that request. Please try again.