Hello,
I am using CForm builder.
I’d like to add the opening and closing unordered list tags around my list of checkboxes.
How do I proceed ?
Here’s my piece of code that should be in an UL :
...
'relatedItems' => array(
'type' => 'checkboxlist',
'items' => $this->getRelatedItemList(),
'template' => '<li>{label} {input}</li>'
),
...
Thank you in advance
joblo
(Joe)
2
Maybe try:
...
'<ul>',
'relatedItems' => array(
'type' => 'checkboxlist',
'items' => $this->getRelatedItemList(),
'template' => '<li>{label} {input}</li>'
),
'</ul>',
...
Hmm no, this solution you are mentionning would add the ul tags at the wrong level.
But yii user marcovtwout put me back on the right track and in the end I am using a widget.
In that widget I use the run() method to render my CHhtmlcheckboxlist wrapped in the UL.
...
$content = '<ul class="sortableCheckboxList">';
$content .= CHtml::activeCheckBoxList($this->model, $this->attribute, $this->getListData(), array(
'template' => '<li><div class="dragHandle" style="">drag here</div>{label} {input}</li>'));
$content .= '</ul>';
...
spikyjt
(Spikyjt)
4
Better still, use the layout, template and separator properties like this:
'relatedItems' => array(
'type' => 'checkboxlist',
'items' => $this->getRelatedItemList(),
'layout' => '{label} <ul class="sortableCheckboxList">{input}</ul> {hint} {error}',
'template' => '<li><div class="dragHandle" style="">drag here</div>{label} {input}</li>',
'separator' => ' ',
),
‘layout’ applies to the overall list layout, where {input} is actually the list of inputs.
‘template’ applies to each checkbox, as you know (hence hint and error are not used).
We override ‘separator’ because it defaults to ‘<br>’ which would be bad news for styling here.