Skip to content
This repository has been archived by the owner on Sep 28, 2020. It is now read-only.

Getting the autocomplete array from an external service #340

Open
ppazos opened this issue Feb 7, 2019 · 2 comments
Open

Getting the autocomplete array from an external service #340

ppazos opened this issue Feb 7, 2019 · 2 comments

Comments

@ppazos
Copy link

ppazos commented Feb 7, 2019

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
Copy link

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
Copy link

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants