yii2 radio inline Html helper

2019-06-26 03:41发布

问题:

I have this radioList in yii2

Html::radioList('abc',null,$new,['class' => 'form-control input-sm']);

It generates this:

<div class=radio>

but I want:

<div class=radio-inline>

please help me

回答1:

No. Let's say that $new = [1 => 'Hello', 2 => 'World'];

The generated output will be:

<div class="form-control input-sm">
    <label>
        <input type="radio" name="abc" value="1"> Hello
    </label>

    <label>
        <input type="radio" name="abc" value="2"> World
    </label>
</div>

If you want to add radio class to container tag you can do it like that:

echo Html::radioList('abc', null, $new, ['class' => 'form-control input-sm radio']);

For each input it will be:

echo Html::radioList('abc', null, $new, [
    'class' => 'form-control input-sm',
    'itemOptions' => ['class' => 'radio'],
]);

Check the documentation, it's pretty clear.



回答2:

I think this is proper solution

<?= $form->field($model, 'abc')->inline()->radioList(['example1' => 'example1', 'example2' => 'example2'])->label(false) ?>


标签: php yii2