php - Select2 dropdown with dynamic name and image in yii2
I am working on yii2.
I have form with many fields.
I have one field that which has name and image.
I want to display that with select2 dropdown with name and image. Name is coming but how to display image in that dropdown.
Yii view file code :
<?php $form = ActiveForm::begin(); ?>
<div class="col-xs-6 col-md-5">
<?= $form->field($model,'db_fieldname')->dropDownList(['0'=>'Select category']
+ ArrayHelper::map(Category::find()->all(),'id','name'),
['multiple'=>'multiple']) ?>
</div>
<?php ActiveForm::end(); ?>
I have wrote JS : At the end of my view file
<?php
$this->registerJs('$("select").select2( templateResult: format);');
?>
Now according to above code please guide me how to display image in dropdown.
Answer
Solution:
Take look Here... Might be helpful to you.
https://select2.github.io/examples.html#templating