I am returning cat_id value by GET in url to say that my dropdown list, which Item must be select. But it's not working.
<?= $form->field($model, 'cat_id')->dropDownList(
ArrayHelper::map(DeviceCats::find()
->where(['is_deleted' => 'no'])->all(),'id','title')
,['options' => [$_GET['cat_id'] => ['selected'=>true]]
, 'prompt' => ' -- Select Category --']) ?>
Finally solved with an unbelievable change. Just changed the first letter of selected to capital ('selected' should be 'Selected'). Here is the code:
<?= $form->field($model, 'cat_id')->dropDownList(
ArrayHelper::map(DeviceCats::find()
->where(['is_deleted' => 'no'])->all(),'id','title')
,['options' => [$_GET['cat_id'] => ['Selected'=>'selected']]
, 'prompt' => ' -- Select Category --']) ?>
'Selected' must be written with a capital letter 'S':
'options'=>['72'=>['Selected'=>true]]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With