Using Remote Data For Autocomplete With Alpaca Forms
Solution 1:
First to show key values correctly and not an array of keys you have to use Bloodhound, so before initializing alpaca use bloodhound to filter and process your data like this :
var data = newBloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: 'http://smart-api.info/api/suggestion/field=services.inputParameter.parameterDataType',
filter: function(data) {
// Map the remote source JSON array to a JavaScript object arrayreturn $.map(data.field_values.buckets, function(bucket) {
return {
value: bucket.key
};
});
}
}
});
data.initialize();
Then in your alpaca config set displayKey
to value
and source
to data.ttAdapter()
"datasets": {
"name": "data",
"displayKey": 'value',
"source": data.ttAdapter()
}
With this I don't get the wanted value, because the problem here is with the datasource you're using, I tried to use another datasource that uses the %QUERY string and it worked perfectyl. For this kind of datasource I tried to use local
instead of remote
and it worked. Try it yourself and tell me if it works.
Here's some mock datasource examples :
- (http://www.alpacajs.org/docs/endpoints/typeahead-sample.php?q=%QUERY)
- (http://api.themoviedb.org/3/search/movie?query=%QUERY&api_key=f22e6ce68f5e5002e71c20bcba477e7d)
And here's a fiddle, I added another datasource that uses a %QUERY string, try to use local and remote in data
(see the comments) and try next to use the other datasource movies
in alpaca config.
Hope this helps.
Post a Comment for "Using Remote Data For Autocomplete With Alpaca Forms"