sliptree / bootstrap-tokenfield

A jQuery tag/token input plugin for Twitter's Bootstrap, by the guys from Sliptree
http://sliptree.github.io/bootstrap-tokenfield/
Other
859 stars 238 forks source link

Getting the autocomplete array from an external service #340

Open ppazos opened 5 years ago

ppazos commented 5 years ago

I can't find in the current documentation how can I set the autocomplete array dynamically from, for instance, an AJAX call to a backend service.

I need to provide a narrowed down list of possibilities since the amount of possible tags is about 10K! can't load that every time on the UI. Also I might need to show only 10-15 possible tags if the search on the server retrieves more than that to make the UI not show 100's of texts in the dropdown.

Is there some sample code on how to do this? Thanks a lot.

Lintzman commented 4 years ago

This is an old post but here is a sample to get a list of tags via an AJAX call

$("#Tags").tokenfield({
        delimiter: "|",
        minLength: 1,
        autocomplete: {
            minLength: 2,
            delay: 500,
            source: function (request, response) {
                $.ajax(
                    {
                        url: "YourUrlToGetTags"
                        dataType: "json",
                        data: {
                            searchTerm: request.term,
                        },
                        success: function (data) {
                            response(data);
                        }
                    });
            }

        }
    });
gharaszti71 commented 4 years ago

The main problem of this solution when you want to use value/label pairs as token. You'll get a value list if you fill the field with a separator separated value list. How to sole this?