For the second option above, the Zend_Form::_defaultElementDecorators
variable should be an associative array of element names to decorators, for
example:

array(
        'Element' => array(// decorators), // Special case, applies to elements
without default decorators.
        'Text' => array(// decorators),
        'Date' => array(// decorators)
)

setDefaultElementDecorators(array $decorators, $elementType = null)

This is what I'm using:

<?php

class App_Form_BaseForm extends Zend_Form
{
    protected $_defaultElementDecorators = array(
        'Element' => array(
            'ViewHelper',
            'Label',
            array('Errors', array('placement' => 'prepend')),
            array(array('row' => 'HtmlTag'), array('tag' => 'div'))
        ),
        'Hash' => array('ViewHelper'),
        'Submit' => array(
            'ViewHelper', array('HtmlTag', array('tag' => 'div', 'class' =>
'form-buttons'))
        )
    );

    public function loadDefaultDecorators()
    {
        if ($this->loadDefaultDecoratorsIsDisabled()) {
            return;
        }

        $decorators = $this->getDecorators();
        if (empty($decorators)) {
            $this->addDecorators(array(
                'FormElements',
                array('Description', array('placement' => 'prepend')),
                'Form'
            ));
        }
    }

    public function createElement($type, $name, $options = null)
    {
        if (!isset($options['decorators'])) {
            if (isset($this->_defaultElementDecorators[$type])) {
                $options['decorators'] =
$this->_defaultElementDecorators[$type];
            } else {
                $options['decorators'] =
$this->_defaultElementDecorators['Element'];
            }
        }

        $element = parent::createElement($type, $name, $options);

        return $element;
    }
}
-- 
View this message in context: 
http://n4.nabble.com/How-to-set-the-default-decorators-for-form-elements-tp1290314p1556488.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to