Decorators again

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

Decorators again

umpirsky
Hi.

I'm trying to do the following thing.

I have some form, and I'm putting elements on it one by one, when I finish, I call setElementDecorators() to customize rendering. That works perfect, but now I want to add decorator to 3rd element, but setElementDecorators() owerwrites them, if I call setElementDecorators before adding elements, it takes no effect!

How can I achieve this without setting decorators for each element one by one?

Regards,
Sasa Stamenkovic.
Reply | Threaded
Open this post in threaded view
|

Re: Decorators again

umpirsky
I need something like addElementDecorators() :D

Regards,
Saša Stamenković


On Tue, Sep 29, 2009 at 3:46 PM, umpirsky <[hidden email]> wrote:

Hi.

I'm trying to do the following thing.

I have some form, and I'm putting elements on it one by one, when I finish,
I call setElementDecorators() to customize rendering. That works perfect,
but now I want to add decorator to 3rd element, but setElementDecorators()
owerwrites them, if I call setElementDecorators before adding elements, it
takes no effect!

How can I achieve this without setting decorators for each element one by
one?

Regards,
Sasa Stamenkovic.
--
View this message in context: http://www.nabble.com/Decorators-again-tp25663367p25663367.html
Sent from the Zend Framework mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: Decorators again

SpiffyJr
On 9/29/2009 8:51 AM, Саша Стаменковић wrote:
I need something like addElementDecorators() :D

Regards,
Saša Stamenković


On Tue, Sep 29, 2009 at 3:46 PM, umpirsky <[hidden email]> wrote:

Hi.

I'm trying to do the following thing.

I have some form, and I'm putting elements on it one by one, when I finish,
I call setElementDecorators() to customize rendering. That works perfect,
but now I want to add decorator to 3rd element, but setElementDecorators()
owerwrites them, if I call setElementDecorators before adding elements, it
takes no effect!

How can I achieve this without setting decorators for each element one by
one?

Regards,
Sasa Stamenkovic.
--
View this message in context: http://www.nabble.com/Decorators-again-tp25663367p25663367.html
Sent from the Zend Framework mailing list archive at Nabble.com.


See http://devzone.zend.com/article/3450. Specifically,

"Unfortunately, there are not currently methods for inserting decorators at specific locations in the decorator stack, so if you find you need to insert a new decorator in the middle of the stack, the best way is to simply reset the stack. For example, if you wanted to add a Description following the element (perhaps a paragraph detailing the purpose of the element), you could do the following:

$element->setDescription($desc);
$element->setDecorators(array(
    'ViewHelper',
    'Description',
    'Errors',
    array('HtmlTag', array('tag' => 'dd')),
    array('Label', array('tag' => 'dt')),
));
While addDecorator() and addDecorators() methods exist, typically you will be using setDecorators() unless you start out with very minimal decorators to begin with."

-- 
Kyle Spraggs (SpiffyJr)
http://www.spiffyjr.me
Kyle S
blogs @ www.spiffyjr.me
github @ www.github.com/spiffyjr
follow @ www.twitter.com/spiffyjr
Reply | Threaded
Open this post in threaded view
|

Re: Decorators again

Alayn Gortazar
In reply to this post by umpirsky
Have you tried with something like:

$form->setElementDecorators(
        .
        .
        .
);
$form->third_element_name->setDecorators(
        .
        .
        .
);

I think it should work...
 
El mar, 29-09-2009 a las 06:46 -0700, umpirsky escribió:

> Hi.
>
> I'm trying to do the following thing.
>
> I have some form, and I'm putting elements on it one by one, when I finish,
> I call setElementDecorators() to customize rendering. That works perfect,
> but now I want to add decorator to 3rd element, but setElementDecorators()
> owerwrites them, if I call setElementDecorators before adding elements, it
> takes no effect!
>
> How can I achieve this without setting decorators for each element one by
> one?
>
> Regards,
> Sasa Stamenkovic.

Reply | Threaded
Open this post in threaded view
|

Re: Decorators again

umpirsky
Fatal error: Call to a member function addDecorator() on a non-object in...

Regards,
Saša Stamenković


On Tue, Sep 29, 2009 at 4:34 PM, alayn <[hidden email]> wrote:
Have you tried with something like:

$form->setElementDecorators(
       .
       .
       .
);
$form->third_element_name->setDecorators(
       .
       .
       .
);

I think it should work...

El mar, 29-09-2009 a las 06:46 -0700, umpirsky escribió:
> Hi.
>
> I'm trying to do the following thing.
>
> I have some form, and I'm putting elements on it one by one, when I finish,
> I call setElementDecorators() to customize rendering. That works perfect,
> but now I want to add decorator to 3rd element, but setElementDecorators()
> owerwrites them, if I call setElementDecorators before adding elements, it
> takes no effect!
>
> How can I achieve this without setting decorators for each element one by
> one?
>
> Regards,
> Sasa Stamenkovic.


Reply | Threaded
Open this post in threaded view
|

Re: Decorators again

umpirsky
Solution found! Look at the setElementDecorators() description:

/**
     * Set all element decorators as specified
     *
     * @param  array $decorators
     * @param  array|null $elements Specific elements to decorate or exclude from decoration
     * @param  bool $include Whether $elements is an inclusion or exclusion list
     * @return Zend_Form
     */
    public function setElementDecorators(array $decorators, array $elements = null, $include = true)

there is 2nd parameter, where you can specify which elements to include/exclude from setting decorators, so you can aviod owerwriting decorators for some desired elements :)

Regards,
Saša Stamenković


On Wed, Sep 30, 2009 at 7:49 AM, Саша Стаменковић <[hidden email]> wrote:
Fatal error: Call to a member function addDecorator() on a non-object in...

Regards,
Saša Stamenković



On Tue, Sep 29, 2009 at 4:34 PM, alayn <[hidden email]> wrote:
Have you tried with something like:

$form->setElementDecorators(
       .
       .
       .
);
$form->third_element_name->setDecorators(
       .
       .
       .
);

I think it should work...

El mar, 29-09-2009 a las 06:46 -0700, umpirsky escribió:
> Hi.
>
> I'm trying to do the following thing.
>
> I have some form, and I'm putting elements on it one by one, when I finish,
> I call setElementDecorators() to customize rendering. That works perfect,
> but now I want to add decorator to 3rd element, but setElementDecorators()
> owerwrites them, if I call setElementDecorators before adding elements, it
> takes no effect!
>
> How can I achieve this without setting decorators for each element one by
> one?
>
> Regards,
> Sasa Stamenkovic.



Reply | Threaded
Open this post in threaded view
|

Re: Decorators again

umpirsky
One more question.

This decorators I use for rendering <select>

$decorators = array(
'Label',
'ViewHelper',
array('HtmlTag', array('tag' => 'div', 'class' => 'slider'/*, 'placement' => 'prepend'*/)),
);

rendered:

<div class="slider">
<label for="price" class="optional">xxx:</label>

<select name="price" id="price">
    <option value="0" label="0">0</option>
</select>
</div>
I want this:
<label for="price" class="optional">xxx:</label>
<div class="slider">
<select name="price" id="price"> <option value="0" label="0">0</option>
</select>
</div>
How can I hammer it out?
Regards,
Saša Stamenković


On Wed, Sep 30, 2009 at 8:52 AM, Саша Стаменковић <[hidden email]> wrote:
Solution found! Look at the setElementDecorators() description:

/**
     * Set all element decorators as specified
     *
     * @param  array $decorators
     * @param  array|null $elements Specific elements to decorate or exclude from decoration
     * @param  bool $include Whether $elements is an inclusion or exclusion list
     * @return Zend_Form
     */
    public function setElementDecorators(array $decorators, array $elements = null, $include = true)

there is 2nd parameter, where you can specify which elements to include/exclude from setting decorators, so you can aviod owerwriting decorators for some desired elements :)

Regards,
Saša Stamenković



On Wed, Sep 30, 2009 at 7:49 AM, Саша Стаменковић <[hidden email]> wrote:
Fatal error: Call to a member function addDecorator() on a non-object in...

Regards,
Saša Stamenković



On Tue, Sep 29, 2009 at 4:34 PM, alayn <[hidden email]> wrote:
Have you tried with something like:

$form->setElementDecorators(
       .
       .
       .
);
$form->third_element_name->setDecorators(
       .
       .
       .
);

I think it should work...

El mar, 29-09-2009 a las 06:46 -0700, umpirsky escribió:
> Hi.
>
> I'm trying to do the following thing.
>
> I have some form, and I'm putting elements on it one by one, when I finish,
> I call setElementDecorators() to customize rendering. That works perfect,
> but now I want to add decorator to 3rd element, but setElementDecorators()
> owerwrites them, if I call setElementDecorators before adding elements, it
> takes no effect!
>
> How can I achieve this without setting decorators for each element one by
> one?
>
> Regards,
> Sasa Stamenkovic.