php - Select2 dropdown with dynamic name and image in yii2

530

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.

636

Answer

Solution:

Take look Here... Might be helpful to you.

https://select2.github.io/examples.html#templating

People are also looking for solutions to the problem: php - Zend File Validator multiple file error

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.