Style for QListItem
Mon, 05/24/2010 - 12:22
Hi,
I am trying to add a class to a QListItem for a QCheckBoxList and cannot, for the life of me, figure out how to add a style. Can someone please help? Here's my code:
<?php
foreach($objCategory->GetChildCategoryArray() as $objChildCat) {
$objListItem = new QListItem($objChildCat->__toString(), $objChildCat->Id, '', '', 'FontBold=true', 'ForeColor=#ff0000', 'CssClass=second-level');
foreach ($objAssociatedArray as $objAssociated) {
if ($objAssociated->Id == $objChildCat->Id)
$objListItem->Selected = true;
}
$this->chkCategories->AddItem($objListItem);
}
?>This doesn't work and doesn't render any styles when I render the QCheckBoxList. Is there something that I need to do to make the styles render?
Thanks for your help,
Chris

try this:
$objListItem->CssClass="second-level";
Thanks for the response, but that doesn't work. I get this error:
Undefined SET property or variable in 'QListItem' class: CssClass
I know there is a QListItemStyle, but I've tried that too and doesn't work. This is what I've tried:
<?php
$objListItem = new QListItem($objChildCat->__toString(), $objChildCat->Id);
$objListItemStyle = new QListItemStyle;
$objListItemStyle->CssClass = "second-level";
$objListItem->ItemStyle = $objListItemStyle;
?>
That didn't work for me either. Any other ideas?
Chris
yes, you're right - QListItemStyle is the right way to do it, I checked in the class definition and there's a CssClass attribute, so that should work.
I'm using version 1.1 - what version are you using?
Yes, but it's just not rendering the style for me. It doesn't print the style on my tpl file. Does it work for you if you do the following?
test.php:
<?php
include('app/includes/prepend.inc.php');
class TestForm extends QForm {
protected $chkList;
protected function Form_Create() {
$this->chkList = new QCheckBoxList($this);
$objListItem = new QListItem('test', 'test');
$objListItemStyle = new QListItemStyle;
$objListItemStyle->CssClass = "second-level";
$objListItem->ItemStyle = $objListItemStyle;
$this->chkList->AddItem($objListItem);
}
}
TestForm::Run('TestForm');
?>
test.tpl.php:
<?php $this->RenderBegin() ?><?php $this->chkList->Render() ?>
<?php $this->RenderEnd() ?>
In the tpl file, I can't see my "second-level" style. Are you able to get this to work?
Thanks,
Chris
you're right - I tested your code and it doesn't print the class attribute. maybe a bug somewhere, right now I can't help you further.
in the meantime, try to do it with javascript - iterate over the items and apply the class attribute.
I've created a ticket for this. Hopefully it will be fixed soon, and if you have any patches or suggestions to supply, please feel free. :)
http://trac.qcu.be/projects/qcubed/ticket/569