简体   繁体   English

yii2 radioList内联表单域

[英]yii2 radioList inline formfield

I have this radioList inline in Yii2: 我在Yii2中有这个radioList内联:

<?= $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: 但我希望标签与单选按钮内联,如下所示:

在此处输入图片说明

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. wrapper选项应用于带有单选按钮的div标签。 The default display is block , causing the div to use al of the available space pushing the label up. 默认显示为block ,导致div使用所有可用空间将标签向上推。 The function inline(true) renders the radio buttons in one line. 函数inline(true)将单选按钮呈现为一行。

You can use template option of field method: 您可以使用field方法的template选项:

$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. 把任何你想要的HTML。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM