Here i need to add default selection in radio button(checked).
<?php $form = ActiveForm::begin(['id' => 'login-form']); ?>
<?= $form->field($model, 'email') ?>
<?php if(!empty($usernames)){
echo '<label>Select Any Username To Which You Want To Login</label><div class="all_username">';
foreach ($usernames as $key => $value) { ?>
<?= $form->field($model, 'username[]')->radio(['value' => $value['username'], 'id' => ''])->label($value['username']) ?>
<?php } ?>
</div>
<?= $form->field($model, 'password')->passwordInput() ?>
<?php } ?>
答案 0 :(得分:1)
You need to use following method where 1 is your selected ID.
$form->radioButtonList($model,'1', $usernames, array('separator'=>"" ));
答案 1 :(得分:1)
You can probably use something like this:
foreach ($usernames as $key => $value) {
if(/*somecondition*/){
$model->username = $value['username'];
}?>
<?= $form->field($model, 'username[]')->radio(['value' => $value['username'], 'id' => ''])->label($value['username']) ?>
<?php } ?>
Only by assigning the $model->username
a default value you can choose which radio will be selected.