Matthew Weier O'Phinney-3 wrote:
> 
> However, it is not possible at this time to set attributes on
> the tag surrounding it.
> 

Hello,

some words about me : i am new to Php and to ZF too (1 week), so excuse me
if I say big mistakes :) (and for my french english)

Like Vincent, I have a problem with decorating label, especially, decorating
surrounding label tag.

I modified the Label.php class to support a new option 'classTag' like this
:
line 303 (version 1.5.2)

        if (null !== $tag) {
            require_once 'Zend/Form/Decorator/HtmlTag.php';
            $decorator = new Zend_Form_Decorator_HtmlTag();
            // By default was :
            //$decorator->setOptions(array('tag' => $tag));
            if (!empty($options) && isset($options['classTag'])) {
                $classTag = $options['classTag'];
                $decorator->setOptions(array('tag' => $tag, 'class' =>
$classTag));
            } else {
                $decorator->setOptions(array('tag' => $tag));
            }
            
            $label = $decorator->render($label);
        }

Then i can have the following output :
<td class="labelTd"><label ... /></td>
with the following call :
$inpuDecorator = (array(
    'ViewHelper',
    'Errors',
    array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' =>
'inputTd')),
    array(array('label' => 'Label'), array('tag' => 'td', 'classTag' =>
'labelTd', 'class' => 'labelClasse')),
));
instead of default behavior :
<td><label class="labelTd"... /></td>

@Matthew : 
the problem is that this code generates non valid html code, since label
uses FormElement _htmlAttribs(...) method, and generate this :
<td class="labelTd"><label for="subform2-nationalite" classTag="labelTd"
class="labelClasse optional">Nationalité</label></td>

Is this 'bug' being fixed ?
Or what is the best way to implement this behavior, and making valid html
code ?

Regards
-- 
View this message in context: 
http://www.nabble.com/Adding-styles-to-labels-using-Zend_Form-tp17733774p18468423.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to