Issues

ZF-6741: Decorators and id attribute

Issue Type: Task Created: 2009-05-20T05:54:11.000+0000 Last Updated: 2013-03-13T20:55:23.000+0000 Status: Open Fix version(s): - Next Mini Release ()

Reporter: Bob Gaudaen (bgaudaen) Assignee: Christian Albrecht (alab) Tags: - Zend_Form

Related issues: Attachments:

Description

In the default element decorators, the id attribute is set for the wrapping dd tag

<pre class="highlight">
                ->addDecorator('HtmlTag', array('tag' => 'dd',
                                                'id'  => $this->getName() . '-element'))

getName() should be replaced by getId() because the name of an element is not always unique.

The same issue appears in the DtDdWrapper decorator where the element name is taken for the ids.

Comments

Posted by Christian Albrecht (alab) on 2010-04-20T11:28:51.000+0000

Simply replacing getName() with getId() has not the effect you wish it to have, because the Id gets assembled only when rendering within FormElements Decorator.

So i am suggesting this solution, please give me your opinions.

<pre class="highlight">
    public function loadDefaultDecorators()
    {
        if ($this->loadDefaultDecoratorsIsDisabled()) {
            return;
        }

        $decorators = $this->getDecorators();
        if (empty($decorators)) {
            $getId = create_function('$decorator',
                                     'return $decorator->getElement()->getId()
                                             . "-element";');
            $this->addDecorator('ViewHelper')
                ->addDecorator('Errors')
                ->addDecorator('Description', array('tag' => 'p', 'class' => 'description'))
                ->addDecorator('HtmlTag', array('tag' => 'dd',
                                                'id'  => array('callback' => $getId))
                ->addDecorator('Label', array('tag' => 'dt'));
        }
    }



<pre class="highlight">
    protected function _htmlAttribs(array $attribs)
    {
        $xhtml = '';
        $enc   = $this->_getEncoding();
        foreach ((array) $attribs as $key => $val) {
            $key = htmlspecialchars($key, ENT_COMPAT, $enc);
            if (is_array($val)) {
                if (array_key_exists('callback', $val)
                    && is_callable($val['callback'])) {              //added is_callable in r21970
                    $val = $val['callback']($this);
                }
                else {
                    $val = implode(' ', $val);
                }
            }
            $val    = htmlspecialchars($val, ENT_COMPAT, $enc);
            $xhtml .= " $key=\"$val\"";
        }
        return $xhtml;
    }

Posted by Christian Albrecht (alab) on 2010-04-20T11:43:34.000+0000

Fix For SubTask ZF-7663

<pre class="highlight">
...
        if (null !== $tag) {
            require_once 'Zend/Form/Decorator/HtmlTag.php';
            $decorator = new Zend_Form_Decorator_HtmlTag();
            $decorator->setOptions(array('tag' => $tag,
                                         'id'  => $this->getElement()->getId() . '-label'));

            $label = $decorator->render($label);
        }
...

Posted by Christian Albrecht (alab) on 2010-04-21T14:40:45.000+0000

Solution of first comment applied to trunk r21964, sheduling for next minor release.

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