Hello.

I've been playing with Zend_Form today, specifically with the text
decorators, however it's not behaving quite how I expect.

I've extended the Zend_Form class, and I create the form using an array of
options, like so:
class forms_MediaOutletForm extends Zend_Form
{

        public function __construct($options = null) {

                $loader = Zend_Registry::get('loader');

                $loader->load('FormUtils');

                parent::__construct(array(
                        'action' => '/mediaoutlet/process',
                        'method' => 'post',
                        'decorators' => array(
                                'FormElements',
                                array('HtmlTag', array('tag' => 'p')),
                                ),
                        'elementDecorators' => array(
                                        array('ViewHelper'),
                                        array('Errors'),
                                        array('Label', array(
                                                'requiredSuffix' => ' *',
                                                'class' => 'leftalign',
                                        )),
                                        array('HtmlTag', array('tag' =>
'div', 'class' => 'field')),
                                ),
                        'elements' => array(
                                'MediaOutletId' => array('hidden', array(
                                        'validators' => array(
                                                'digits',
                                        ),
                                        'readonly' => true,
                                )),
                                'Name' => array('text', array(
                                        'validators' => array(
                                                array('stringLength', false,
array(3,70)),
                                        ),
                                        'filters' => array('StringTrim'),
                                        'required' => true,
                                        'label' => 'Name',
                                )),
                                'CompanyID' => array('select', array(
                                        'validators' => array(
                                                'notEmpty',
                                        ),
                                        'required' => true,
                                        'MultiOptions' =>
Companies::getIDName(array("Publisher")),
                                        'label' => 'Publisher',
                                        'decorators' =>  array(
                                                array('ViewHelper'),
                                                array('Errors'),
                                                array('Label', array(
                                                        'requiredSuffix' =>
' XXX',
                                                        'class' =>
'leftalign',
                                                )),
                                                array('DivTag' => 'HtmlTag',
array('tag' => 'div', 'id' => 'company_div' )),
                                        )
                                )),
),
                ));
        }
}

What's happening is that the specific element decorate is being overridden
due to the setOptions method in Zend/Form.php doing this:
$this->setElementDecorators($elementDecorators);

after all the elements are set.  This is causing my specific element
decorators to be overridden.

Does anyone have any ideas on how I can do what I'm wanting while staying
with this method of form configuration?

Cheers,
Jonathan.
-- 
View this message in context: 
http://www.nabble.com/Zend_Form-global-decorators-overriding-per-element-decorators-when-using-array-of-options-to-construct-tp17105287p17105287.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to