Selected options in multiple drop-down list

Hi,

The following code doesn’t work.




<?= $form->field($modelUserCountry, 'id')->dropDownList(

	ArrayHelper::map(Country::find()->all(), 'id', 'code'), ['multiple' => true, 'options' => ['1' => ['selected' => true], '2' => ['selected' => true]]]

) ?>



The content of ArrayHelper::map(Country::find()->all(), ‘id’, ‘code’) is:




Array ( [1] => fd [2] => aa )



The saving with viaTable() an link() works fine, but not the displaying of the selected options after saving.

Can anybody help me? Thanks a lot.

Alex

Hello jogger,

I think the code should be something like this :

<?= $form->field($modelUserCountry, ‘id’)->dropDownList(

    ArrayHelper::map(Country::find()-&gt;all(), 'id', 'code'), ['multiple' =&gt; true, 'selected'=&gt;'selected']

) ?>

thanks

Hi,

It doesn’t work.

What should I do, that in a multiple drop-down list the stored values are selected?

Alex

Hi,

Nobody an idea?

I’m using ActiveForm with an multiple dropDownList().

Saving works, but after saving the saved entries are not selected.

Alex