Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend Form - Set class on a label's dt

Update I was able to get this to work by creating a custom Label decorator, which extended Zend/Form/Decorator/Label.php. I added a setTagClass() method to it and overrode the render method to create the enclosing tag with the desired class. There might be a more elegant way to do it but this seems to work.

I'm looking for information on how to set the class on a label's dt element using a decorator. The third line of code below sets the class on the label and wraps the label in a dt tag. I want to know how I can set the class on the dt tag.

$txtLangPrefOther = $this->createElement('text','langPrefOther');
$txtLangPrefOther->setLabel('Language Preference Other:'));
$txtLangPrefOther->getDecorator('Label')->setOptions(array('tag' => 'dt', 'class' => 'other'));

This produces output such as

<dt id="langPrefOther-label">
   <label for="langPrefOther" class="other">Language Preference Other:</label>
</dt>

<dd id="langPrefOther-element">
   <input type="text" id="langPrefOther" name="langPrefOther" ">
</dd>

I want it to look like

<dt id="langPrefOther-label" class="other">
   <label for="langPrefOther">Language Preference Other:</label>
</dt>

<dd id="langPrefOther-element">
   <input type="text" id="langPrefOther" name="langPrefOther" ">
</dd>
like image 644
Chris Avatar asked Mar 04 '10 22:03

Chris


2 Answers

There is a property of the Label decorator called tagClass!

Try this out:

$element->addDecorators(array( 
'ViewHelper', 
'Description',
'Errors',
array('HtmlTag', array('tag' => 'dd', 'class' => $class )),
array('Label', array('tag' => 'dt', 'class' => $class, 'tagClass' => $class))
));
like image 163
sami Avatar answered Sep 29 '22 10:09

sami


Because it's a form decorator not element decorator. Try this:

$this->setDecorators(
array(
'FormElements',
array('HtmlTag', array('tag' => 'dl', 'class' => 'theclass')),
'Form'
));
like image 29
cnkt Avatar answered Sep 29 '22 09:09

cnkt