Issues

ZF-12493: Zend_Form not using elementDecorators when elements passed to addElement|s are Zend_Form_Element instance - FIX

Description

Setting Zend_Form elementDecorators in options (constructor, setOptions) does not affect elements added to form by Zend_Form::addElement/s if passed elements are Zend_Form_Element instance.

Sorry, I don't have dev account (my first patch ;) ) so I just post my patch here - elementDecorators from Zend_Form are only loaded if Zend_Form_Element doesnt have any decorators set (You have to use disableLoadDefaultDecorators)

h3. PATCH

Zend_Form.php (add lines 1035-1039)


$elementDecorators = $element->getDecorators(); //prior php 5.5 compatibility
if (empty($elementDecorators) && !empty($this->_elementDecorators)) { 
   $element->setDecorators($this->_elementDecorators); 
}

h3. Example (with subforms where I stumbled on this bug)

instead:


$sub = new Zend_Form_Subform(array(
   'elements' => array(
      new Zend_Form_ElementText(
         'name' => 'email',
         'label' => 'Email:'
      )
   )
));

//fyi twitter bootstrap horizontal form decorators
$sub->setElementDecorators(
array(array('input' => 'ViewHelper')),
array(array('controls' => 'HtmlTag'), array('tag' => 'div', 'class' => 'controls')),
array(array('label' => 'Label'), array('class' => 'control-label')),
array(array('control-group' => 'HtmlTag'), array('tag' => 'div', 'class' => 'control-group', 'placement'=> false)),
);


$this->addSubForm($sub, 'user');

we have:


$this->addSubForm(
   'elements' => array(
      new Zend_Form_ElementText(
         'name' => 'email',
         'label' => 'Email:'
         'disableLoadDefaultDecorators' => true //if not set default decorators will be used
      )
   ),
   'elementDecorators' => array(
      array(array('input' => 'ViewHelper')),
      array(array('controls' => 'HtmlTag'), array('tag' => 'div', 'class' => 'controls')),
      array(array('label' => 'Label'), array('class' => 'control-label')),
      array(array('control-group' => 'HtmlTag'), array('tag' => 'div', 'class' => 'control-group', 'placement'=> false)),
),
'user');

Thank You for Your attention, Bye ;]

//v

Comments

No comments to display