Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to preselect/check a default radio button in yii2 RadioList()?

I want the radio button preselected in my form.

 <?= $form->field($model, 'config')->radioList(['1'=>'Automatic Entry',2=>'Manual Entry'])
     ->label('Barcode/Book No Generation'); ?>
like image 376
Insane Skull Avatar asked Jul 11 '15 09:07

Insane Skull


1 Answers

The preselected values are taken from $model->config. That means that you should set that attribute to the value that you want preselected :

$model->config = '1';
$form->field($model, 'config')->radioList([
    '1' => 'Automatic Entry',
    '2' => 'Manual Entry',
]);

The relevant doc for this is in the ActiveForm class.

like image 84
tarleb Avatar answered Sep 27 '22 17:09

tarleb