Skip to content

Commit c9d106b

Browse files
author
Tomas Kirda
committed
Update documentation.
1 parent 4ca8fc3 commit c9d106b

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

readme.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The standard jquery.autocomplete.js file is around 2.7KB when minified via Closu
1414
* `options`: An object literal which defines the settings to use for the autocomplete plugin.
1515
* `serviceUrl`: Server side URL or callback function that returns serviceUrl string. Optional if local lookup data is provided.
1616
* `ajaxSettings`: Any additional [Ajax Settings](http://api.jquery.com/jquery.ajax/#jQuery-ajax-settings) that configure the jQuery Ajax request.
17-
* `lookup`: Lookup array for the suggestions. It may be array of strings or `suggestion` object literals.
17+
* `lookup`: Callback function or lookup array for the suggestions. It may be array of strings or `suggestion` object literals.
1818
* `suggestion`: An object literal with the following format: `{ value: 'string', data: any }`.
1919
* `lookupFilter`: `function (suggestion, query, queryLowerCase) {}` filter function for local lookups. By default it does partial string match (case insensitive).
2020
* `lookupLimit`: Number of maximum results to display for local lookup. Default: no limit.
@@ -115,6 +115,27 @@ $('#autocomplete').autocomplete({
115115
});
116116
```
117117

118+
Custom lookup function:
119+
```javascript
120+
121+
$('#autocomplete').autocomplete({
122+
lookup: function (query, done) {
123+
// Do ajax call or lookup locally, when done,
124+
// call the callback and pass your results:
125+
var results = [
126+
{ "value": "United Arab Emirates", "data": "AE" },
127+
{ "value": "United Kingdom", "data": "UK" },
128+
{ "value": "United States", "data": "US" }
129+
];
130+
131+
done(results);
132+
},
133+
onSelect: function (suggestion) {
134+
alert('You selected: ' + suggestion.value + ', ' + suggestion.data);
135+
}
136+
});
137+
```
138+
118139
##Styling
119140

120141
Generated HTML markup for suggestions is displayed bellow. You may style it any way you'd like.

0 commit comments

Comments
 (0)