Issues

ZF-7663: SubForm decorators are not properly namespaced

Description

Here is an example which illustrates this issue: $form = new Zend_Form;

$checkbox = new Zend_Form_Element_Checkbox('checkbox1', array('label'=>'checkbox 1')); $form->addElement($checkbox); $checkbox = new Zend_Form_Element_Checkbox('checkbox2', array('label'=>'checkbox 2')); $form->addElement($checkbox);

$subform1 = new Zend_Form_SubForm('subform1');

$checkbox = new Zend_Form_Element_Checkbox('checkbox1', array('label'=>'checkbox 1')); $subform1->addElement($checkbox); $checkbox = new Zend_Form_Element_Checkbox('checkbox2', array('label'=>'checkbox 2')); $subform1->addElement($checkbox);

$form->addSubForm($subform1, 'subform1');

This produces the following HTML:

checkbox 1
checkbox 2
checkbox 1
checkbox 2

As you can see, id attributes are duplicated.

Comments

To fix duplicate

change in Zend_View_Helper_Label: line 317: 'id' => $this->getElement()->getName() . '-label'));

to: 'id' => $id. '-label'));

I do not know, how to fix duplicates in

. This is where default HtmlTag decorator dd is added. Now to fix this, I add HtmlTag decorator with custom id.

To fix duplicate in

the defaults decorators are set in Zend_Form_Element: loadDefaultDecorators() line 291 (ZF 1.9.0) public function loadDefaultDecorators() { if ($this->loadDefaultDecoratorsIsDisabled()) { return; } $decorators = $this->getDecorators(); if (empty($decorators)) { $this->addDecorator('ViewHelper') ->addDecorator('Errors') ->addDecorator('Description', array('tag' => 'p', 'class' => 'description')) ->addDecorator('HtmlTag', array('tag' => 'dd')) ->addDecorator('HtmlTag', array('tag' => 'dd', 'id' => $this->getName() . '-element')) ->addDecorator('Label', array('tag' => 'dt')); } } I try to use $this->getId() instead of $this->getName() but it didn't work so i just remove the 'id' attrib from the HtmlTag decorator: ->addDecorator('HtmlTag', array('tag' => 'dd')) Cheers Tomas Guemes

I suggest a patch in Zend_Form_Decorator_Label to fix this issue. SVN diff attached.

Regards, Saša Stamenković

Why nobody is reviewing my patch. Tell me if its wrong.

Resolving as duplicate of ZF-6741.