Setting decorators options for form elements in config

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Setting decorators options for form elements in config

Cristian Bichis-4
Hi,

I often encounter this small problem when working with forms.

My forms configs are array based and sometime I would like to change
some of the decorator options.

One sample is when I want the Description to contain a link to a page.
With default behaviour the escape is escaping the link. I can easily
change this with this:

$this->getElement('terms')->getDecorator('Description')->setOption('escape',
false);

But I would like to actually have this set in my form config directly.

However, if I only set the description one decorator (see below) the
other decorators are not loaded anymore...

                 'terms' => array(
                     'type' => 'checkbox',
                     'options' => array(
                         'validators' => array(
                             'validator' => 'IsChecked'
                         ),
                         'required' => true,
                         'ignore' => true,
                         'label' => 'Terms of use',
                         'description' => 'I agree to the <a
target="_blank" href="/uri">Terms of use</a>',
                         'decorators' => array(
                             'description' => array(
                                 'decorator' => 'Description',
                                 'options' => array(
                                     'tag' => 'p',
                                     'class' => 'description',
                                     'escape' => false,
                                 )
                             ),
                         )
                     )
                 ),


There is any way from config to only overwrite one decorator without
removing the others?

If I try to set all then there are additional issues, how do I set
correctly the htmlTag id option to be OK (below is a wrong sample).

                             'htmltag' => array(
                                 'decorator' => 'htmlTag',
                                 'options' => array(
                                     'tag' => 'dd',
                                     'id'  => array('callback' =>
array(get_class($this), 'resolveElementId'))
                                     )
                             ),

I tried using 'disableLoadDefaultDecorators' => false, in element config
but doesn't appear to work...

Thank you,
Cristian
Reply | Threaded
Open this post in threaded view
|

Re: Setting decorators options for form elements in config

Frank Brückner
Am 31.08.2012, 11:36 Uhr, schrieb Cristian Bichis <[hidden email]>:

> However, if I only set the description one decorator (see below) the
> other decorators are not loaded anymore...

The config key "decorators" calls the method "setDecorators" and this  
method need all decorators for an element.

> There is any way from config to only overwrite one decorator without
> removing the others?

In the config file: no.


Simple solution for your problem: set the "escape" option for all  
"description" decorators to "false".


Kind regards,
Frank

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Setting decorators options for form elements in config

Cristian Bichis-4
Hi Frank,

Thank you for your solution.

If I still set all decorators in config any idea what should I use for
html tag to have the id working properly? Below I just pasted the
array('callback' => array(get_class($this), 'resolveElementId')) taken
from code (which obviously won't work properly):

                              'htmltag' => array(
                                  'decorator' => 'htmlTag',
                                  'options' => array(
                                      'tag' => 'dd',
                                      'id'  => array('callback' =>
array(get_class($this), 'resolveElementId'))
                                      )
                              ),

Cristian Bichis

> Am 31.08.2012, 11:36 Uhr, schrieb Cristian Bichis <[hidden email]>:
>
>> However, if I only set the description one decorator (see below) the
>> other decorators are not loaded anymore...
> The config key "decorators" calls the method "setDecorators" and this
> method need all decorators for an element.
>
>> There is any way from config to only overwrite one decorator without
>> removing the others?
> In the config file: no.
>
>
> Simple solution for your problem: set the "escape" option for all
> "description" decorators to "false".
>
>
> Kind regards,
> Frank
>


--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Setting decorators options for form elements in config

Frank Brückner
In reply to this post by Cristian Bichis-4
Am 31.08.2012, 11:36 Uhr, schrieb Cristian Bichis <[hidden email]>:

> One sample is when I want the Description to contain a link to a page.
> With default behaviour the escape is escaping the link. I can easily
> change this with this:
>
> $this->getElement('terms')->getDecorator('Description')->setOption('escape',
> false);
>
> But I would like to actually have this set in my form config directly.

I added a workaround to your issue in the tracker:  
http://framework.zend.com/issues/browse/ZF-12401

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]