arashr
(Caman Ws)
February 3, 2013, 8:54am
1
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 (conditional).
l.jurgs
(L Jurgs)
February 3, 2013, 10:04am
2
The only way you are going to get what you want here is too implement a custom algorithm, the checkBoxList does support a template option but it has no conditional support (you’d need to be able to pass in a callback or similar).
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 (conditional).
arashr
(Caman Ws)
February 3, 2013, 10:52am
3
I know it. What I don’t know is HOW?!
l.jurgs
(L Jurgs)
February 3, 2013, 11:10am
4
I’m only trying to help.
Anyway.
It really depends if you want something re-usable or a one off edge case. I can point you in the right direction but I cannot write your software for you.
Something one off could work like this:
foreach ($models as $model) {
echo '<input type="checkbox" name="' . CHtml::activeName($model, 'attribute') . '[]" value="' . $model->valueField . '" ' . condition ? 'class= "your-class" : '' . '/>';
}
Refactor or massage to suit.