CreativeBulma / bulma-tagsinput

Bulma's extension providing user interface to manage tags supporting autocomplete.
MIT License
62 stars 21 forks source link

Question about option "source" #21

Open thomascenni opened 3 years ago

thomascenni commented 3 years ago

Hi, In case of Dynamic data source, using the code supplied in the documentation:

<script>
    document.addEventListener('DOMContentLoaded', function() {
        const tagsInput = document.getElementById('tags-with-source');
        new BulmaTagsInput(tagsInput, {
            source: async function(value) {
                // Value equal input value
                // We can then use it to request data from external API
                return await fetch("https://restcountries.eu/rest/v2/name/" + value)
                    .then(function(response) {
                        return response.json();
                    });
            }
        });
    }, false);
</script>

it is not clear to me how data should be returned from the server. I have a JSON object like this:

[{"name":"Allemand","text":"Allemand"},{"name":"Animateur D'Art","text":"Animateur D'Art"}]

returned from my server, and it's not rendered correctly (it appears in the list as undefined). Thanks in advance, any help is really appreciated.

illwrks commented 1 year ago

For my future self...

[
    {
        "value":"1",
        "text":"Allemand"
    },
    {
        "value":"2",
        "text":"Animateur D'Art"
    }
]