Yii2 checkbox list item format
<?= Html::activeCheckboxList($model, 'yiilib_role', AuthRole::getAuthRoleList(),
[
'tag'=>'ul',
'class'=>'role-select',
'item'=>function ($index, $label, $name, $checked, $value){
$itemString = '';
if ($index % 4 == 0) {
$itemString .= "<li>";
}// each 4 items in one li, here is begin li
// set checked attribute
if ($checked) {
$itemString .= "<label>
<input type='checkbox' name='$name' checked value='$value'>$label</label>";
}else{
$itemString .= "<label>
<input type='checkbox' name='$name' value='$value'>$label</label>";
}
// each end li and the last end li
if (($index+1) % 4 == 0 && $index != 0) {
$itemString .= "</li>";
}else{
if (($index+1) == count(AuthRole::getAuthRoleList())) {
$itemString .= "</li>";
}
}
return $itemString;
}
]); ?>
Leave Comment