Hello guys,
I’m trying to work with dropDownList from ActiveField…but i’m missing something with the “options Array”.
That’s my main code from _form.php file. What i wanna do is to make selected option tag based on array.
$servizi = Servizi::find()->all();
$serviziLista = ArrayHelper::map($servizi,'idservizio','nome');
$selected = [
'1' => ['selected' => 'selected'],
'2' => ['selected' => 'selected'],
'3' => ['selected' => 'selected'],
];
<?= $form->field($model, 'servizi_attivi')->dropDownList(
['' => $serviziLista ],
[
//'prompt'=> 'Please select',
'options' => $selected,
'multiple' => true,
'size' => '5',
]
);
?>
but the output doesn’t care about my “option array”…none of my options tag is being selected.
<select size="5" multiple="" name="Clienti[servizi_attivi][]" class="form-control" id="clienti-servizi_attivi">
<optgroup label="">
<option value="1">Proxy/Firewall</option>
<option value="2">Voip</option>
<option value="3">Antivirus Centralizzato</option>
</optgroup>
</select>
I tried different way to test it like changing selected in true, i have read a lot of docs…dunno what to do now.
Thx for help anyway