简体   繁体   English

Yii框架2中创建radioList时如何自定义外层div?

[英]How to customise outer div when creating radioList in Yii framework 2?

Below is my bootstrap activefield that generates radiolist.下面是生成radiolist的我的引导活动字段。

<?= $form->field($model, 'photo_id')->radioList(['A', 'B', 'C']) ?>

The above code generates the following HTML tags.上面的代码生成以下 HTML 标记。

<div id="model-photo_id">
    <div class="radio">
        <label>
            <input type="radio" name="Model[photo_id]" value="0" checked=""> 
            A
        </label>
    </div>
    <div class="radio">
        <label>
            <input type="radio" name="Model[photo_id]" value="1" checked=""> 
            B
        </label>
    </div>
    <div class="radio">
        <label>
            <input type="radio" name="Model[photo_id]" value="2" checked=""> 
            C
        </label>
    </div>
</div>

The target is <div class="radio"> .目标是<div class="radio"> I would like to customise this div by changing the class name or adding more class name, adding more attributes into this div , ect.我想通过更改类名或添加更多类名来自定义这个 div,在这个div中添加更多属性等。 How can I do that?我怎样才能做到这一点?

You can try with this custom template, instead of applying class to radio div, you can apply class to label also您可以尝试使用此自定义模板,而不是将类应用于单选 div,您也可以将类应用于标签

echo $form->field($model, 'photo_id')
        ->radioList(
                [0 => 'A', 1 => 'B', 2 => 'C'], [
            'item' => function($index, $label, $name, $checked, $value) {

                $return = '<label class="modal-radio">';
                $return .= '<input type="radio" name="' . $name . '" value="' . $value . '" tabindex="3">';
                $return .= '<i></i>';
                $return .= '<span>' . ucwords($label) . '</span>';
                $return .= '</label>';

                return $return;
            }
                ]
        )
        ->label(false);

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

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