I want to show selected value in Yii2 dropdown,
$_GET Value:
$id = $_GET["cid"];
Drop down code
$form->field($model, 'userid')
->dropDownList(
[User::getUser()],
//[ArrayHelper::map(User::findAll(['active' => '1']), 'id', 'name')],
['prompt'=>'Select a user','id'=>'user_dropdown'],
['options' =>
[
$id => ['selected' => true]
]
]
)->label('');
but this method is not working!
Show activity on this post. $form->field($model, 'userid') ->dropDownList( [User::getUser()], //[ArrayHelper::map(User::findAll(['active' => '1']), 'id', 'name')], ['prompt'=>'Select a user','id'=>'user_dropdown'], ['options' => [ $id => ['selected' => true] ] ] )->label(''); but this method is not working! Arah..
If you use $model as the model for the dropdownlist you'll save the ID of the selected value to the database. So then when you're going to update the record, the $model->prj_id will be set to the saved value, so that is the value it will display.
Try this.
$model->userid=$id;
$form->field($model, 'userid')
->dropDownList(...)
->label('');
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