Issues

ZF-12405: Zend_Form_Element Need an option to set default decorators globally

Issue Type: New Feature Created: 2012-09-05T11:18:35.000+0000 Last Updated: 2012-09-05T13:02:56.000+0000 Status: Closed Fix version(s): Reporter: shamseer (shamseerss) Assignee: Frank Brückner (frosch) Tags: - Zend_Form

Related issues: - ZF-12387

Attachments:

Description

Now when creating a Form Element, if there is no default decorators are specified, the following code add default decorators

<pre class="highlight">
$this->addDecorator('ViewHelper')
 ->addDecorator('Errors')
->addDecorator('Description', array('tag' => 'p', 'class' => 'description'))
->addDecorator('HtmlTag', array(
    'tag' => 'dd',
      'id'  => array('callback' => array(get_class($this), 'resolveElementId'))
))->addDecorator('Label', array('tag' => 'dt'));

Need an option to set default Decorators globally rather than current option, Some thing like a static function to set default decorators.

Comments

Posted by Frank Brückner (frosch) on 2012-09-05T12:19:42.000+0000

We have already Zend_Form::setElementDecorators(). (API-Docs)

Posted by shamseer (shamseerss) on 2012-09-05T12:40:07.000+0000

I already tried this function. Zend_Form::setElementDecorators() function will remove all current decorators in element. and we have call it after adding all form elements. and add particular decorator for each decorators. If we have more forms a global option will be better.

Posted by Frank Brückner (frosch) on 2012-09-05T12:53:13.000+0000

Here is a simple example:

<pre class="highlight">
$form = new Zend_Form();
$form->setDecorators(
    array(
        'FormElements',
        'Form'
    )
);
$form->setElementDecorators(
    array(
        'Label',
    )
);

$form->addElement(
    'text',
    'foo',
    array(
        'label' => 'Foo',
    )
);
$form->addElement(
    'text',
    'bar',
    array(
        'label' => 'Bar',
    )
);
$form->addElement(
    'submit',
    'baz',
    array(
        'label'      => 'Baz',
        'decorators' => array(
            'ViewHelper',
        ),
    )
);

echo $form->render(new Zend_View());



<pre class="highlight">

    Foo
    Bar
    

Where is the problem?

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