How can I set the class for a <dt> element in a Zend_Form?
I'm trying to set the width of the style for a group of < dt > elements in a Zend_Form. Is there a way to set a class for a dt element, so the end result would be something like this:
<dt id="name-label" class="xyz" > // trying to add the 'class="xyz"
<label class="required" for="name">Name:</label>
</dt>
<dd id="name-element">
<input type="text" maxlength="255" size="30" value="" id="name" name="name">
</d开发者_高级运维d>
Try something like this:
<form id='ID_FOR_FORM' method="post" action="">
<ul>
<li>
<dt><label for="your-name">Your Name:</label></dt>
<dd><input type="text" size="40" id="your-name" value="" name="your-name" /></dd>
</li>
<li>
<dd><input type="submit" type='button' value="Send" /></dd>
</li>
</ul>
</form>
Then in your css you dont need any classes or id for child elements of that form, you can simply go something like this for that dt:
form#ID_FOR_FORM ul li dt{
margin:0;
padding:0;
}
That is how i like to work with css, make good markup, and then i dont need classes or id's, just do what i did in this example. :)
I finally found the solution - i needed to wrap the dt,dd elements in a < dl > tag and set the class of the < dl > tag. then i set the css for the < dt > elements through the < dl > class, like so:
Sample element:
$question = new Zend_Form_Element_TextArea('question'.$i);
$question->setLabel('Question '.$i.':')
->setAttrib('rows', 10)->setAttrib('cols', 40)->setAttrib('class', 'richtexteditor')
->addFilter('StringTrim')
->addDecorator('HtmlTag', array('tag' => 'dd','id'=> 'question'.$i.'-element',
'style'=>'width:350px;max-height:202px;'
)
)
->addDecorator(array('dlTag'=>'HtmlTag'), array('tag' => 'dl','class'=> 'xyz')) //added this line
->addDecorator('Errors', array('class'=>'custom-errors'))
->setOptions(array('onkeyup'=>'textCounter();',
'onkeydown'=>'textCounter();'
)
);
Then, i added the following to my css file:
dl.xyz{
margin: 0;
}
.xyz dt {
width:97px;
padding-left: 0px;
margin-left: -15px;
}
this achieves what i was aiming for all along - modifying certain dt elements' style while retaining a general/default < dt >style for the entire form.
精彩评论