Reputation: 171
I have this radioList inline in Yii2:
<?= $form->field($model, 'abc')->inline(true)->radioList(array('1'=>'yes',2=>'no')); ?>
It generated:
<div class="form-group field-minstitution-abc">
<label class="control-label" for="abc">Abc</label>
<div>
<div id="abc">
<label class="radio-inline">
<input type="radio" name="abc" value="1"> yes
</label>
<label class="radio-inline">
<input type="radio" name="abc" value="2"> no
</label>
</div>
</div>
</div>
But I want the label inline with the radio button like this:
Upvotes: 4
Views: 11777
Reputation: 1236
Use the folowing code.
form->field($model, 'abc',
['wrapperOptions' => ['style' => 'display:inline-block']])
->inline(true)->radioList(array('1'=>'yes',2=>'no'));
The wrapper option is applied to the div
tag with surrounds the radio buttons. The default display is block
, causing the div to use al of the available space pushing the label up. The function inline(true)
renders the radio buttons in one line.
Upvotes: 5
Reputation: 8072
You can use template
option of field
method:
$form->field($model, 'abc', '<div class=\"radio\">\n{beginLabel}
{input}\n{labelTitle}\n{endLabel}\n{error}\n{hint}\n</div>')
->radioList(array('1'=>'yes',2=>'no')); ?>
Put any html what you want.
Upvotes: -2