Skip to content Skip to sidebar Skip to footer

Using Remote Data For Autocomplete With Alpaca Forms

I'm using Alpaca forms and pulling values for a form autocomplete field from a web service. I've worked through how to use this data as values for the autocomplete using jQuery and

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 localinstead of remote and it worked. Try it yourself and tell me if it works.

Here's some mock datasource examples :

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"