Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add "alts", so you can pass in an object of { value: "value", alts: […

… alts ] }, and the item will show up if any are matched.
  • Loading branch information...
commit 3868c2320d059d29938b50149324d4d0b25aa1be 1 parent 8211e43
@aaronm67 aaronm67 authored
Showing with 18 additions and 7 deletions.
  1. +2 −2 scripts/demo.js
  2. +16 −5 src/jquery.autocomplete.js
View
4 scripts/demo.js
@@ -9,8 +9,8 @@ $(function () {
dataType: 'json'
}).done(function (data) {
var status = $('#selection'),
- countries = $.map(data, function (value) {
- return value;
+ countries = $.map(data, function (value, idx) {
+ return { value: value, alts: [ idx.toString() ] };
});
$('#query').autocomplete({
View
21 src/jquery.autocomplete.js
@@ -263,8 +263,7 @@
},
getSuggestionsLocal: function (q) {
- var ret, arr, len, val, i;
-
+ var ret, arr, len, val, i, j, option, options;
arr = this.options.lookup;
len = arr.suggestions.length;
ret = { suggestions: [], data: [] };
@@ -272,9 +271,21 @@
for (i = 0; i < len; i++) {
val = arr.suggestions[i];
- if (val.toLowerCase().indexOf(q) === 0) {
- ret.suggestions.push(val);
- ret.data.push(arr.data[i]);
+ if ($.isPlainObject(val) && val.value && val.alts) {
+ options = [ val.value ].concat(val.alts);
+ val = val.value;
+ }
+ else {
+ options = [ val ];
+ }
+
+ for (j = 0; j < options.length; j++) {
+ option = options[j];
+ if (option.toLowerCase().indexOf(q) === 0) {
+ ret.suggestions.push(val);
+ ret.data.push(arr.data[i]);
+ break;
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.