smart 2018-01-17 13:40:44 4455次浏览 0条评论 3 0 0

先吐槽下yii2 不能修改已发布的教程
这边补充前面的ActiveForm 表单知识点

1,ActiveForm 中的checkboxList样式

我想修改checkboxList下的每个checkbox的样式

这边可以使用两个itemOptions和item
itemOptions :生成每个checkbox的参数选项.

// 我这边是用html生成的,不要问我怎么用ActiveForm生成
<?= Html::checkboxList('children', [], $permissions, ['class' => 'col-lg-5','itemOptions'=>array('style'=>'margin:10px')]); ?>

item : 在生成每个checkbox表单的时候,都会回调这个函数,如果设置了则使用返回值作为checkbox的表单,否则使用static::checkbox函数来生成每个checkbox表单,函数格式为:
function ($index, $label, $name, $checked, $value)

<?= Html::checkboxList('children', [], $permissions, ['class' => 'col-lg-5', 
    'item' => function ($index, $label, $name, $checked, $value) {
        $checkStr = $checked ? "checked" : "";
        return '<label><input type="checkbox" style="margin:10px" name="' . $name . '" value="' . $value . '" ' . $checkStr . ' class="class' . $index . '" data-uid="user' . $index . '">' . $label . '</label>';
}]); ?>
    没有找到数据。
您需要登录后才可以评论。登录 | 立即注册