A
A
Alexander2015-10-09 16:55:20
Yii
Alexander, 2015-10-09 16:55:20

How to make selected in DropDownList?

<?php $listData = ArrayHelper::map(\backend\models\Category::find()->all(), 'id', 'name'); ?>
        <?= $form->field($aticleCategory, 'category_id')->dropDownList(
            $listData,
            [
                'prompt' => 'Select...',
                'multiple' => 'true',
                'options' => array(1=>array('selected'=>'selected'))
            ]
        ); ?>

in Browser
<select id="categoryarticle-category_id" class="form-control" name="CategoryArticle[category_id][]" multiple="true" size="4">
<option value="">Select...</option>
<option value="1">Book</option>
<option value="2">Films</option>
</select>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2015-10-10
@kentuck1213

Solved the issue, it was necessary to write ['Selected' => true]
Capitalized

M
Max, 2015-10-09
@AloneCoder

<?php $listData = ArrayHelper::map(\backend\models\Category::find()->all(), 'id', 'name'); ?>
        <?= $form->field($aticleCategory, 'category_id')->dropDownList(
            $listData,
            [
                'prompt' => 'Select...',
                'multiple' => 'true',
                'options' => array(1=>array('selected'=>'selected'))
            ]
        )->label(''); ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question