2008年11月29日星期六

Re: [fw-mvc] Zend_Form : How to set a class for the label wrapper?

Sorry for the delay.
It works gracefully!
Thanks!

--
Ramses Paiva
Software Architect
Sourcebits Technologies
www.sourcebits.com

On Thu, Nov 20, 2008 at 5:00 PM, Mon Zafra <monzee@gmail.com> wrote:
You can't pass options to the HtmlTag decorator used internally by the Label decorator, so you have to change the default decorators in order to accomplish this.
$decors = array(
'ViewHelper',
'Errors',
array('Description', array('tag' => 'p', 'class' => 'description')),
array('HtmlTag', array('tag' => 'dd')),
array(array('labelDtClose' => 'HtmlTag'),
array('tag' => 'dt', 'closeOnly' => true, 'placement' => 'prepend')),
'Label',
array(array('labelDtOpen' => 'HtmlTag'),
array('tag' => 'dt', 'openOnly' => true, 'placement' => 'prepend', 'class' => 'clear'))
);
$fieldEmail = $form->createElement(
    'text',
    'email',
    array('label' => 'Email:', 'decorators' => $decors)
)->setRequired(true);

   -- Mon



On Thu, Nov 20, 2008 at 3:58 PM, Ramses Paiva <ramses@sourcebits.com> wrote:
Hi list,


I'd like to set a class attribute for the label wrapper element and I'm not being able to do this.

My code:

$form =
new Zend_Form();

$fieldEmail = $form->createElement(
    'text',
    'email',
    array('label' => 'Email:')
)->setRequired(true);

$fieldEmail->getDecorator('Label')->setOption('class', 'clear');


What I'm getting is:

<dt>
    <label for="email" class="required clear">Email:</label>
</dt>

<dd>
    <input type="text" value="" id="email" name="email"/>
</dd>


And what I'd like to have is:

<dt class="clear">
    <label for="email" class="required">Email:</label>
</dt>

<dd>
    <input type="text" value="" id="email" name="email" />
</dd>


Any help? Ideas?


Best regards,

--
Ramses Paiva
Software Architect
Sourcebits Technologies
www.sourcebits.com

没有评论: