add value to select2 4 - empty entry becomes visible

39 views Asked by At

I have a select2 control in which I am adding data. It's working well, the data is added.

However, the empty option that existed in the select suddenly becomes visible, wheras it's notin the beginning (norally you click the select 2 cross at the right of the control to erase your choice).

How can I do to make sure the empty option does not become visible when adding data ?

My code :

    <a href="#/" class="btn btn-primary" id="launch">Lancer</a>
    <script>
        $(function(){
            $('#launch').on('click', function(){
                var $select2 = $('#appbundle_job_offer_contact');
                $select2.select2({data: [{id: 'dada', text:'dada' }]});
            });
        });
    </script>

enter image description here

I have a feedle here which shows how the empty option is displayed : https://jsfiddle.net/v1skjwqy/1/

0

There are 0 answers