ZF-7182: Incorrect behaviour in Zend_Form_Decorator_Label

Description

The docs for this decorator state: "You may optionally specify a 'tag' option; if provided, it wraps the label in that block-level tag. If the 'tag' option is present, and no label present, the tag is rendered with no content. You can specify the class to use with the tag with the 'class' option or by calling setClass(). "

However, passing the 'class' option or calling setClass actually sets the class for the label, not the tag which wraps it, severely limiting the utility of the tag option.

Suggested fix: add a 'tagClass' option.

Comments

Fix: added tagOptions option to Zend_Form_Decorator_Label. These options are then passed to the HtmlTag decorator which wraps the label tag. These options do not overwrite the tag or id options specified in Zend_Form_Decorator_Label::render

Also attached is a test for this change.

This is my first patch / test so any feedback welcome.

I wonder if the existing options should be updated to reflect the tagOptions functionality instead of actually adding tagOptions.

When specifying the label, you can set all of the class / id / etc attributes as you wish. I don't know if there is really a need for two interfaces to a single set of attributes.

Just a thought.

You can set the attributes (class, etc.) for the label in the existing options; what you cannot currently do is set the attributes for the optional tag which wraps the label. Further, the docs state that you can set the tag class using setClass() - this is not true.

So you can currently create markup like:

My Label

What the docs state you can do, and my patch implements, is to create markup like

My Label

And my patch also allows you to have arbitrary attributes to the tag like

My Label

Cheers, Mark

There is already a solution: {{Zend_Form_Decorator_Label::setTagClass()}}

You can find an example here: zfforum.de (in German)