radioList: how to check default radio.button

How to default check a radio button in a radio list??


 $form->field($model, 'attribut1')->radioList(['name1'=>'value1', 'name2'=>'value2'],[]);

the 2nd array is the options

Just set the default value to the model.




$model->attribut1 = 'value1';

...

$form->field($model, 'attribut1')->radioList(['value1'=>'name1', 'value2'=>'name2'],[]);



$items should be an array where the values are the labels, and the keys are the values.

I mean "valeu => name", not "name => value".

http://www.yiiframework.com/doc-2.0/yii-bootstrap-activefield.html#radioList()-detail

1 Like