Represents a list of radio buttons with a single selection.
Form model:
final class ProfileForm extends FormModel
{
public string $color = 'red';
public function getAttributeLabels(): array
{
return [
'color' => 'Select color',
];
}
public function getAttributeHints(): array
{
return [
'color' => 'Your personal color.',
];
}
}
Widget:
echo RadioList::widget()
->formAttribute($profileForm, 'color')
->items([
'f00' => 'Red',
'0f0' => 'Green',
'00f' => 'Blue',
]);
Result will be:
<div>
<label>Select color</label>
<div>
<label><input type="radio" name="ProfileForm[color]" value="f00" checked> Red</label>
<label><input type="radio" name="ProfileForm[color]" value="0f0"> Green</label>
<label><input type="radio" name="ProfileForm[color]" value="00f"> Blue</label>
</div>
<div>Your personal color.</div>
</div>
string
- number or numeric string (see is_numeric())
bool
null
- any stringable values