mdbootstrap / bootstrap-templates

A collection of free Bootstrap 5 templates.
https://mdbootstrap.com/freebies/
3.07k stars 1.02k forks source link

input value attribute not being honoured when using objects tags with typeahead #623

Closed JamesRoche closed 2 years ago

JamesRoche commented 6 years ago

I am doing teh following.

<input class="form-control" data-tags-data="[{&quot;value&quot;:&quot;...&quot;,&quot;text&quot;:&quot;None..&quot;},{&quot;value&quot;:&quot;OB-LINK:2:4&quot;,&quot;text&quot;:&quot;Employment Opportunities&quot;},{&quot;value&quot;:&quot;OB-LINK:2:6&quot;,&quot;text&quot;:&quot;test category&quot;}]" data-th="json" data-val="true" id="taggedcategories" name="taggedcategories" placeholder="" title="" type="text" value="OB-LINK:2:6" style="display: none;">

This is my input, im binding the typahead to the json in teh data-tags-json attribute. This is workign fien for adding new tags and saving them etc.

However when i reload the page i can see the original input has teh correct value(OB-LIN:2:6 above) but after the taginput is created there is no initial tags present. I create the input as follows.

`    $('[data-th=json]').each(function (i, ob) {
        console.log('found tags ds');
        var current = $(ob).val().split(',');
        var rawData = $(ob).attr("data-tags-data");
        console.log(JSON.parse(rawData));
        var data = JSON.parse(rawData);
         var ti = $(ob).tagsinput({
            typeahead: {
                source: JSON.parse(rawData),
                hint: true,
                displayKey: 'text'
            },

            itemText: function (item) { return item.text; },
            itemValue: function (item) { return item.value; },
            freeInput: false
        }); 
    });`

It seems there is an issue binding the value attribute to the data objexts in my source array.

Cheers.

James