Adding a css class to specific items of Yii active checkBoxList

对着背影说爱祢 提交于 2020-01-04 10:09:26

问题


Working with Yii and active checkboxlist. I know the params. I need to add a flag css class to the items. This is my code:

$form->checkBoxList($model, 'items', $selected, array(
    'class'=>'default_class'
));

This code just adds a default_class to every item. But I need a different class for specific items.


回答1:


@XIII, I had updated my answer

$form->checkBoxList($model, 'items', $selected, array(
  'options' => array(
       'value1'=>array('disabled'=>true, 'label'=>'value 1'),
       'value2'=>array('label'=>'value 2', 'class' => 'css-class-defined'),
   ),
));

Please read docs about function what you used, or see source code system.web.helpers.CHtml line 764




回答2:


Asked the same question in the Yii forum. Someone helped me with this solution

foreach ($models as $model) {
  echo '<input type="checkbox" name="' . CHtml::activeName($model, 'attribute') . '[]" value="' . $model->valueField . '" ' . condition ? 'class= "your-class" : '' . '/>';
}

This is a good lead for now.



来源:https://stackoverflow.com/questions/14661164/adding-a-css-class-to-specific-items-of-yii-active-checkboxlist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!