kartik-v / yii2-widget-select2

Enhanced Yii2 wrapper for the Select2 jQuery plugin (sub repo split from yii2-widgets).
http://demos.krajee.com/widget-details/select2
Other
323 stars 145 forks source link

Select 2 data array with additional fields to customize the templateResult #237

Closed lmsmartins closed 6 years ago

lmsmartins commented 6 years ago

How to translate this into the Yii2 select2 kartik widget? I think the "data" attribute from the widget only allows for id -> text. Is this snipped of code possible using the widget?

    var data = [{
       id: 0,
       text: 'enhancement',
        html: '<div style="color:green">enhancement</div>'
    }, {
       id: 1,
       text: 'bug',
        html: '<div style="color:red">bug</div><div><small>This is some small text on a new line</small></div>'
    }];

    function template(data) {
        return data.html;
    }

    $("select").select2({
       data: data,
       templateResult: template,
       escapeMarkup: function(m) {
          return m;
       }
    });
kartik-v commented 6 years ago

Duplicate to #238