Answer the question
In order to leave comments, you need to log in
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'))
]
); ?>
<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
Solved the issue, it was necessary to write ['Selected' => true]
Capitalized
<?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 questionAsk a Question
731 491 924 answers to any question