4

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

Dat Lam
  • 161
  • 1
  • 6
  • 17

2 Answers2

5

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.

Tibor Nagy
  • 1,185
  • 1
  • 15
  • 28
-2

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.

Alex
  • 8,055
  • 7
  • 39
  • 61