jeudi 23 février 2017

How to not add the a checkbox to the "optgroup" of a select2 wen injecting the checkbox input

i'm using Select2 with checkboxes injecting like the following :

<select id="select" style="width: 300px;" multiple="multiple">
        <optgroup label="Inclure Group">
            <option>red</option>
            <option>green</option>
            <option>blue</option>
        <optgroup label="Exclure group">
            <option>yellow</option>
            <option>white</option>
            <option>black</option>
</select>

here is the injectiong :

$j("#select").select2({
                        templateResult: function (data) {
                            var $res = $j('<span></span>');
                            var $check = $j('<input type="checkbox" />');

                            $res.text(data.text);
                            if (data.element) {
                                console.log(data.element);
                                $res.prepend($check);
                                $check.prop('checked', data.element.selected);
                            }
                            return $res;
                        },
                        closeOnSelect: false
})

this manner allows me to inject checbkoxes to all the options and the optgroup which i wanna do not add checkboxes ;

enter image description here

how can i evitate this ??




Aucun commentaire:

Enregistrer un commentaire