Issues

ZF-10065: Radio Element adds a Label decorator automatically

Issue Type: Bug Created: 2010-06-28T06:09:25.000+0000 Last Updated: 2012-07-30T13:58:38.000+0000 Status: Closed Fix version(s): Reporter: Goran Juric (gog) Assignee: Frank Brückner (frosch) Tags: - Zend_Form

Related issues: - ZF-11517

Attachments:

Description

When using radio element with a custom decorator (for example view script decorator) and you do not set the disableLoadDefaultDecorators flag to true the element adds a label decorator to the element.

This is not consistent with how other elements work, and in my case it causes the element to render an extra label decorator.

Commit 22151 in the Subversion changed the way Zend_Form_Element_Radio loads decorators.

What has changed can be seen here: http://framework.zend.com/code/browse/… and the commit message refers to the issue ZF-9682.

Comments

Posted by Boyan Krastev (masterbo) on 2010-08-10T01:44:38.000+0000

Adding a simple check if there are decorators set will fix the issue.

Also the @return type is wrong. Should be Zend_Form_Element_Radio.

<pre class="highlight">

    /**
     * Load default decorators
     *
     * Disables "for" attribute of label if label decorator enabled.
     *
     * @return void
     */
    public function loadDefaultDecorators()
    {
        if ($this->loadDefaultDecoratorsIsDisabled()) {
            return $this;
        }

        /**
         * Check if there are decorators set
         */
        $decorators = $this->getDecorators();
        if (!empty($decorators)) {
            return $this;
        }

        parent::loadDefaultDecorators();
        $this->addDecorator('Label', array('tag' => 'dt',
                                           'disableFor' => true));
        return $this;
    }

Posted by Simon Corless (sico) on 2010-12-08T14:21:56.000+0000

Why not check for a label decorator and if there is one set the disableFor attribute to true. If there isn't a label then add the default one as normal and set the disableFor.

<pre class="literal"> 

As an additional problem this also overwrites any changes you make such as to the requiredSuffix and optionalSuffix.

In fact could the whole method be changed to the following:

public function loadDefaultDecorators() { parent::loadDefaultDecorators();

    if (!($label = $this->getDecorator('Label'))) {
        return $this;
    }

    $label->setOption('disableFor', true);

    return $this;
}````

The parent::loadDefaultDecorators(); takes care of the first if() in the new method itself. Then you just check for a label and disable the for option.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts