vendredi 4 octobre 2019

How can I add icon or a html on select2 selected option not from the option list

What I want to achieve is enter image description here

It work perfectly fine if i select one option from list of options. But on update I want to set it manually not with javascript but from html when the page loads. The option value is dynamic.

<option value="1" selected><i class="fa fa-user"></i>Rakesh shrestha</option>

here the name Rakesh Shrestha and the value = 1 is dynamic.. I'm using php. It is escaping my html i only get

<option value="1" selected>Rakesh shrestha</option>

and hence no icon.

Select2 init:

$('.allSiteSelect2').select2({
        width : "100%",
        placeholder : 'Site',
        escapeMarkup: function(markup) {
            return markup;
        },
        templateResult: function(data) {
            return data.text;
        },
        templateSelection: function(data) {
            return data.text;
        },
        ajax : {..}
}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire