A
A
Alexander Gorkin2018-08-07 00:04:04
Yii
Alexander Gorkin, 2018-08-07 00:04:04

How can each radio set its own id?

Here is the code:

<?php $orders->status = '0'; echo $form->field($orders, 'status')->radioList([
                    '0' => 'Физическое лицо',
                    '1' => 'Юридическое лицо',
                ]);?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-08-07
@mrbagfreeman

Good morning.
You can assign an id to each radio like this

<?= $form->field($model, 'test')->radioList([1 => 'test1', 2 => 'test2'], [
    'item' => function($index, $label, $name, $checked, $value){
          return Html::radio($name, false, ['id' => 'id_' . $index, 'label' => $label]);
    }
])->label(false) ?>

Here the second parameter specifies whether radio is selected by default or not
You can specify that the first radio will be selected by default
Read more here .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question