yii2 radioList inline formfield
10,315
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.
Author by
Dat Lam
Updated on June 27, 2022Comments
-
Dat Lam almost 2 years
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: