Select2 - Update

Hello Everyone!

Searched all over the forum about user Select2 to update values but was not able to solve my problem.

I have a partial with a select2 that is inserting values on database correctly, I’m storing the data as CSV.

On the top of partial, I’m adding this code (using a css library to select2 work with boostrap):

<script>
    $(document).ready(function () {
$('.check-multiple').select2({
    theme: "bootstrap"
});
</script>

To retrieve the infos already on the database, when clicking on <li> tag, on “Static Event” OnClick, I call this script + load a server connect:

<script>
    function myfunc() { 
                        console.log(dmx.parse('conn_findone_servicefeature.data.qry_find_one_servicefeature.service_feature').split(","));
        $('.check-multiple').val([dmx.parse('conn_findone_servicefeature.data.qry_find_one_servicefeature.service_feature').split(",")]).trigger('change');
        
}
</script>

When debugging on Chrome, I got this error:

When I replace “dmx.parse” for values already on my database, for example: [4,5,6], the tags are displayed.

The SC is retrieving data correctly when clicking on the <li> tag.

Thanks in advance and have a great week!

1 Like

Make sure the path to the server connect in your dmx.parse command is correct by checking dmx.app.data in the dev console. For example I always forget to add content. before server connects contained within content views.

1 Like

Hey Ken! Thanks again for your help! You nailed it!
BUT when I have more than one value returned, for example: 2,3, nothing is displayed, only fields with unique values…plus, I follow some tips from another post and changed my script to:

<script>
    function myfunc() {                        
        $(".check-multiple").select2();
        setTimeout(function () {
        $(".check-multiple")
           .val([
              dmx.parse('content.conditional_services.conn_findone_servicefeature.data.qry_find_one_servicefeature.service_feature').split(",")
            ])
        .trigger("change");
        }, 100);
}
</script>

Why when multiple values doesn’t show the tags?

Thanks, mate!

I actually use select2 differently than the example you provide, so I can’t quickly compare the syntax for you. And I’m without power today, so I can’t test what you are doing.

Don’t worry! When you have a time, let me know! :smiley:

Multi select is now available in Wappler, thanks to the Tagify component:
See:

1 Like