Reputation: 978
I'm using yii\bootstrap4\ActiveField::radioList
and I'm trying to insert html tag inside the options of my radioList
.
$list = [
0 => '<strong>Option1</strong><br>
lorem ipsum lorem ipsum',
1 => '<strong>Option2</strong><br>
lorem ipsum lorem ipsum',
2 => '<strong>Option3</strong><br>
lorem ipsum lorem ipsum,',
];
echo $form->field($model, 'field')->radioList($list)->label('Your choose?');
Is there a direct way to do it without create a template ?
Upvotes: 0
Views: 406
Reputation: 23738
What you are looking for is the items
option which gives you the ease to customize the radio
or checkbox
inputs and labels
.
Although it is not clear what layout you are trying to follow for the radioList
but you can change it in the code below, i will focus on what you have mentioned i.e formatting the text labels for the radio-list inputs.
$list = [
0 => '<strong>Option1</strong><br>lorem ipsum lorem ipsum',
1 => '<strong>Option2</strong><br>lorem ipsum lorem ipsum',
2 => '<strong>Option3</strong><br>lorem ipsum lorem ipsum,',
];
echo $form->field($model, 'field')
->radioList(
$list,
[
'item' => function ($index, $label, $name, $checked, $value) {
$html = '<label >';
$html .= '<input type="radio" name="' . $name . '" value="' . $value . '" ' . $checked . '>';
$html .= '<span>' . ucwords($label) . '</span>';
$html .= '</label>';
return $html;
},
]
)
->label('Your choose?');
Upvotes: 1