Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

yii2 radioList inline formfield

Tags:

css

forms

php

yii2

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:

enter image description here

like image 694
Dat Lam Avatar asked Oct 20 '25 14:10

Dat Lam


1 Answers

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.

like image 125
Tibor Nagy Avatar answered Oct 22 '25 03:10

Tibor Nagy