Quantcast

desperately need help with decorators

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

desperately need help with decorators

Mike Wright
Hi all,

For all the Yanks out there, hope you had a great Thanksgiving Day.

Been fighting this for weeks and still don't get it.

What I'm trying to achieve is to wrap each form element in a <dl></dl>
tag.  After much experimenting I ended up with this:

public function setSubFormDecoratorsDl(Zend_Form_SubForm $subForm)
{
     $subForm->setDecorators(
         array(
             array('FormElements',
                    array('separator' => "</dl><dl>"),),   <-------
             array('Form'),
             array('Fieldset'),
         )
     );
}

...trying to get the following:

<fieldset>
   <form>
     <dl>
       <dt><label/></dt>
       <dd><input/></dd>
     </dl>
     <dl>
       <dt><label/></dt>
       <dd><input/></dd>
     </dl>
   </form>
</fieldset>

...but end up with this:

<fieldset>
   <form>
     <dl></dl>    <----- extra, empty <dl/>
     <dl>
       <dt><label>...</label></dt>
       <dd><input/></dd>
     <dl>
     <dl>
       <dt><label>...</label></dt>
       <dd><input/></dd>
     <dl>
   </form>
</fieldset>

If I don't include the separator I end up with all of the FormElements
inside *one* <dl/>.  e.g.

<dl>
   <dt/><dd>
   <dt/><dd>
</dl>

Definitely *not* what I want.

I can use css to hide the superfluous <dl/>, but if the wrapper tag is
instead, e.g. <tr/> or <td/>, it destroys table layouts because of the
extra row or column.

What is the correct way to decorate the FormElements so I don't inject
an empty, extra tag?

I've lost a ton of time trying to figure this out but am afraid I'll
drop dead before I get it ;/

Sign me "desperate".

Thanks for any and all help,
Mike Wright

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


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

RE: desperately need help with decorators

Wilson Revehl (Go Media Inc.)
Don't have them right in front of me but I think you should only be using the open 'dl' tag. But I believe the goal you're aiming for is the default ZF decorator.

$textDecorators = array('ViewHelper', array(array('data' => 'HtmlTag'), array('tag' => 'dd')), array('Label', array('tag' => 'dt')), array('HtmlTag', array('tag' => 'dl')));

-Wil Revehl

-----Original Message-----
From: Mike Wright [mailto:[hidden email]]
Sent: Saturday, November 26, 2011 2:52 PM
To: Zend Framework
Subject: [fw-general] desperately need help with decorators

Hi all,

For all the Yanks out there, hope you had a great Thanksgiving Day.

Been fighting this for weeks and still don't get it.

What I'm trying to achieve is to wrap each form element in a <dl></dl> tag.  After much experimenting I ended up with this:

public function setSubFormDecoratorsDl(Zend_Form_SubForm $subForm) {
     $subForm->setDecorators(
         array(
             array('FormElements',
                    array('separator' => "</dl><dl>"),),   <-------
             array('Form'),
             array('Fieldset'),
         )
     );
}

...trying to get the following:

<fieldset>
   <form>
     <dl>
       <dt><label/></dt>
       <dd><input/></dd>
     </dl>
     <dl>
       <dt><label/></dt>
       <dd><input/></dd>
     </dl>
   </form>
</fieldset>

...but end up with this:

<fieldset>
   <form>
     <dl></dl>    <----- extra, empty <dl/>
     <dl>
       <dt><label>...</label></dt>
       <dd><input/></dd>
     <dl>
     <dl>
       <dt><label>...</label></dt>
       <dd><input/></dd>
     <dl>
   </form>
</fieldset>

If I don't include the separator I end up with all of the FormElements inside *one* <dl/>.  e.g.

<dl>
   <dt/><dd>
   <dt/><dd>
</dl>

Definitely *not* what I want.

I can use css to hide the superfluous <dl/>, but if the wrapper tag is instead, e.g. <tr/> or <td/>, it destroys table layouts because of the extra row or column.

What is the correct way to decorate the FormElements so I don't inject an empty, extra tag?

I've lost a ton of time trying to figure this out but am afraid I'll drop dead before I get it ;/

Sign me "desperate".

Thanks for any and all help,
Mike Wright

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



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


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

RE: desperately need help with decorators

Razorblade
Hi,
try also this solution:

protected $_formElementDecorators = array(  
    'ViewHelper',  
    array( 'Errors', array('escape' => false, 'placement' => 'append' ) ),  
    array( array( 'containerDD' => 'HtmlTag' ), array('tag' => 'dd') ),  
    array( 'Label', array('tag' => 'dt', 'escape' => false ) ),  
    array( array('row' => 'HtmlTag'), array('tag' => 'dl' ) ),  
);

It's the same solution of Wil Revehl, but adds error management.
The error tag, if any, will be rendered right after the "input" html tag.

You must call
$this->setElementDecorators($this->_formElementDecorators);
after you defined all your elements.

The properties of the Errors decorator ( array('escape' => false, 'placement' => 'append' ) ) are there just to let you know they exists.

Hope it helps.

Bye


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

RE: desperately need help with decorators

Mike Wright
On 11/26/2011 02:03 PM, Razorblade wrote:

> Hi,
> try also this solution:
>
> protected $_formElementDecorators = array(
>      'ViewHelper',
>      array( 'Errors', array('escape' =>  false, 'placement' =>  'append' ) ),
>      array( array( 'containerDD' =>  'HtmlTag' ), array('tag' =>  'dd') ),
>      array( 'Label', array('tag' =>  'dt', 'escape' =>  false ) ),
>      array( array('row' =>  'HtmlTag'), array('tag' =>  'dl' ) ),
> );
>
> It's the same solution of Wil Revehl, but adds error management.
> The error tag, if any, will be rendered right after the "input" html tag.
>
> You must call
> $this->setElementDecorators($this->_formElementDecorators);
> after you defined all your elements.
>
> The properties of the Errors decorator ( array('escape' =>  false,
> 'placement' =>  'append' ) ) are there just to let you know they exists.
>
> Hope it helps.

Razorblade, Wilson Revehl,

Helpful and insightful.

I now have this...

    $subForm->setElementDecorators(array(
        array(array('dd' => 'HtmlTag'), array('tag' => 'dd')),
        array(array('dt' => 'Label'),   array('tag' => 'dt')),
        array(array('dl' => 'HtmlTag'), array('tag' => 'dl')),
    ));
    $subForm->setDecorators(array(
        array('elem' => 'FormElements'),
        array('form' => 'Form'),
        array('fset' => 'Fieldset'),
    ));

... which gives perfect markup.

Problem is the <dt><label> tag is fully populated but the corresponding
<dd> is empty.

The labels are there, where are the matching form elements?


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


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

RE: desperately need help with decorators

Razorblade
This post has NOT been accepted by the mailing list yet.
They are rendered by the  'ViewHelper' decorator, add it like in the examples.

Cheers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

RE: desperately need help with decorators

Wilson Revehl (Go Media Inc.)
In reply to this post by Mike Wright
I recommend creating a form wide decorator that meets the need of each element. Here's an example:

class Core_Form_NewAccount extends ZF_form
{

    public $textDecorators = array('ViewHelper', array(array('data' => 'HtmlTag'), array('tag' => 'dd')), array('Label', array('tag' => 'dt')), array('HtmlTag', array('tag' => 'dl')));

 $this->addElement('text', 'fname', array(
        'label' => '*First Name',
            'required'    => true,
            'decorators' => $this->textDecorators  
        ));

You may need to use 'decorators' => self::$textDecorators if it is a real subForm but other than that, not sure why you'd have an issue. There should "decorate", therefore build onto the output of your form class.

-Wil

-----Original Message-----
From: Mike Wright [mailto:[hidden email]]
Sent: Sunday, November 27, 2011 4:08 PM
To: [hidden email]
Subject: Re: [fw-general] RE: desperately need help with decorators

On 11/26/2011 02:03 PM, Razorblade wrote:

> Hi,
> try also this solution:
>
> protected $_formElementDecorators = array(
>      'ViewHelper',
>      array( 'Errors', array('escape' =>  false, 'placement' =>  'append' ) ),
>      array( array( 'containerDD' =>  'HtmlTag' ), array('tag' =>  'dd') ),
>      array( 'Label', array('tag' =>  'dt', 'escape' =>  false ) ),
>      array( array('row' =>  'HtmlTag'), array('tag' =>  'dl' ) ), );
>
> It's the same solution of Wil Revehl, but adds error management.
> The error tag, if any, will be rendered right after the "input" html tag.
>
> You must call
> $this->setElementDecorators($this->_formElementDecorators);
> after you defined all your elements.
>
> The properties of the Errors decorator ( array('escape' =>  false,
> 'placement' =>  'append' ) ) are there just to let you know they exists.
>
> Hope it helps.

Razorblade, Wilson Revehl,

Helpful and insightful.

I now have this...

    $subForm->setElementDecorators(array(
        array(array('dd' => 'HtmlTag'), array('tag' => 'dd')),
        array(array('dt' => 'Label'),   array('tag' => 'dt')),
        array(array('dl' => 'HtmlTag'), array('tag' => 'dl')),
    ));
    $subForm->setDecorators(array(
        array('elem' => 'FormElements'),
        array('form' => 'Form'),
        array('fset' => 'Fieldset'),
    ));

... which gives perfect markup.

Problem is the <dt><label> tag is fully populated but the corresponding <dd> is empty.

The labels are there, where are the matching form elements?


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



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


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

RE: desperately need help with decorators

Mike Wright
On 11/28/2011 06:26 AM, Wilson Revehl (Go Media Inc.) wrote:

> I recommend creating a form wide decorator that meets the need of each element. Here's an example:
>
> class Core_Form_NewAccount extends ZF_form
> {
>
>      public $textDecorators = array('ViewHelper', array(array('data' =>  'HtmlTag'), array('tag' =>  'dd')), array('Label', array('tag' =>  'dt')), array('HtmlTag', array('tag' =>  'dl')));
>
>   $this->addElement('text', 'fname', array(
> 'label' =>  '*First Name',
>             'required'    =>  true,
>             'decorators' =>  $this->textDecorators
>          ));
>
> You may need to use 'decorators' =>  self::$textDecorators if it is a real subForm but other than that, not sure why you'd have an issue. There should "decorate", therefore build onto the output of your form class.
>

Bingo!  The picture becomes clearer...

Thanks to that I now have a subform decorator that renders forms into
tables with a selectable number of columns and which uses javascript to
add and delete rows.

Thanks for all your help, Wil!

Mike

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


Loading...