-- Dalibor Karlović <[email protected]> wrote
(on Monday, 13 July 2009, 11:56 AM +0200):
> I have two selects: fieldName and sortOrder, I'd like to render them like
> 
> <div class="field">
>       <label for="fieldName">Sort by</label>
>       <select id="fieldName" name="fieldName">(...)</select>
>       <select id="sortOrder" name="sortOrder">
>               <option>ASC</option>
>               <option>DESC</option>
>       </select>
> </div>
> 
> and without using the view script for the form (this part is really 
> important, 
> if it wasn't, this wouldn't warrant a question here :) )
> 
> So, the question is: how would you go about it? 

I'd use a DisplayGroup, and assign minimal decorators to each of the
elements:

    $form->addElement('select', 'fieldName', array(
        // ...
        'decorators' => array('ViewHelper', 'Label'),
    ));
    $form->addElement('select', 'sortOrder', array(
        // ...
        'decorators' => array('ViewHelper'),
    ));

    $form->addDisplayGroup(array('fieldName', 'sortOrder'), 'field', array(
        'decorators' => array(
            'FormElements',
            array('HtmlTag', array('tag' => 'div', 'class' => 'field')),
        ),
    ));


> My first idea is to write a 
> decorator called ViewHelpers which would take element names to render, in 
> this 
> case I'd set it to fieldName like this:
> 
> $fieldName->setDecorators(array(
>       'Label',
>       'ViewHelper',
>       array('ViewHelpers, array('elements' => array('sortOrder'))),
>       // rest of it
> ));
> 
> Do you see any obvious flaws in this plan?

Extra complexity. :) Try the above, and see if it accomplishes what
you're trying to do.

-- 
Matthew Weier O'Phinney
Project Lead            | [email protected]
Zend Framework          | http://framework.zend.com/

Reply via email to