Options (<option>
) attributes set as following:
<?php
$form->dropDownList($model,'attr',$data,['options'=>['value1'=>['attr1'=>'attr1 val', 'attr2'=>'attr2 val',]]]);
I want to select option with value 860, like so:
<option value=860 selected>Uzb</option>
I can use following code to achieve this (R::country()
and R::region()
returns list data in array(val=>text,...)
format):
<div class="form-group">
<div class="col-sm-4">
<?= $form->label($model, 'COUNTRY'); ?>
<?= $form->dropDownList($model, 'COUNTRY', R::country(), ['class' => 'form-control', 'options' => ['860' => ['selected' => true],]]); ?>
<?= $form->error($model, 'COUNTRY'); ?>
</div>
<div class="col-sm-4">
<?= $form->label($model, 'REGION'); ?>
<?= $form->dropDownList($model, 'REGION', R::region(), ['class' => 'form-control', 'options' => ['26' => ['selected' => true],]]); ?>
<?= $form->error($model, 'REGION'); ?>
</div>
</div>