link to fiddle : http://jsfiddle.net/nEapJ/ (working)
var items = [{
label : 'a',
value : 'a',
},{
label : 'b',
value : 'b',
},{
label : 'c',
value : 'c',
}];
$('input').autocomplete({
source : items
});
This code works, but when i want to set source by callback function then It's not working
link to fiddle : http://jsfiddle.net/B3RWj/ (not working)
$('input').autocomplete({
source : function(request, response){
response(items);
}
});
when i type, 'a' then its give a,b,c as result.
So, what am I missing?
thanks, in advance.
In the callback function it's up to you to do the filtering..
Extract from documentation:
The third variation, the callback, provides the most flexibility, and can be used to connect any data source to Autocomplete. The callback gets two arguments:
A request object, with a single property called "term", which refers to the value currently in the text input. For example, when the user entered "new yo" in a city field, the Autocomplete term will equal "new yo". A response callback, which expects a single argument to contain the data to suggest to the user. This data should be filtered based on the provided term, and can be in any of the formats described above for simple local data (String-Array or Object-Array with label/value/both properties). It's important when providing a custom source callback to handle errors during the request. You must always call the response callback even if you encounter an error. This ensures that the widget always has the correct state.
see the code:
$('input').autocomplete({
source : function(request, response){
var term = request.term;
var result = [];
//make your code here to filter the item by term.
//put them into the result array such as.
response(result);//this will show in the selection box.
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With