Matthew Weier O'Phinney-3 wrote:
> 
> The short answer is: if you want nesting, use the object that allows for
> it: a sub form. 
>     
> Sub forms are just like regular forms, except for the class name, the
> default decorators, and one or two items of metadata. I have no idea
> what you mean by "you have to set decorators for their elements
> individually"; you can call setElementDecorators() just as easily on a
> sub form as on a regular form.
> 
> Display groups are intended simply for grouping *elements* in a form --
> not sub forms or other groups. The grouping is for cosmetic purposes
> only -- hence the term 'display'. The elements in them actually belong
> to the parent form, so having them namespaced differently is outside
> their scope -- but well within the scope of sub forms (which are
> intended for this kind of logical grouping).
> 
> -- 
> Matthew Weier O'Phinney
> Software Architect       | [EMAIL PROTECTED]
> Zend - The PHP Company   | http://www.zend.com/
> 
> 
You probably don't understand exactly what I want. Take this form:

<form action="" method="post">
Name: <input type="text" name="person_name" ... />
<input type="button" value="Show details" name="show_details"
onclick="document.getElementById('person_details').style.display = 'block';"
/>

<div id="person_details" style="display: none;">
  Age: <input type="text" name="age" .../>
  Favourite color: <input type="text" name="favourite_color" .../>
  Favourite movie: <input type="text" name="favourite_movie" .../>
  <input type="button" value="Show address" name="show_address"
onclick="document.getElementById('address').style.display = 'block';" />

  <div id="address" style="display: none;">
    <input type="text" name="street" ... />
    <input type="text" name="city" ... />
    <input type="text" name="zip_code" ... />
  </div>

</div>

</form>

What I need to do is to display just person name and button do show details.
When button is clicked, details are displayed. Same with address button and
address group. Logically, all elements belong to main form, have same
decorators and other settings. Only difference is, that they are in their
own <div> containers. If I want to do this now, I must use something like
this:

$form = new Zend_Form(array('method'=>'post'));
$form->setElementPrefixPath('My_Decorator', 'My/Decorator', 'decorator');
$form->setElementFilters(array('StringTrim'));
$form->addElement(new Zend_Form_Element_Text(array('name'=>'person_name',
...)));
$form->addElement(new Zend_Form_Element_Button(array('name'=>'show_details',
...)));

// --> Person details =============================
$subForm = new Zend_Form_Subform(array('id' => 'person_details', ...));
$subForm->setElementPrefixPath('My_Decorator', 'My/Decorator', 'decorator');
subFform->setElementFilters(array('StringTrim'));
$subForm->addElement(new Zend_Form_Element_Text(array('name'=>'age', ...)));
$subForm->addElement(new
Zend_Form_Element_Text(array('name'=>'favourite_color', ...)));
$subForm->addElement(new
Zend_Form_Element_Text(array('name'=>'favourite_movie', ...)));
$subForm->addElement(new
Zend_Form_Element_Button(array('name'=>'show_address', ...)));

// --> Address =============================
$subSubForm = new Zend_Form_Subform(array('id' => 'address', ...));
$subSubForm->setElementPrefixPath('My_Decorator', 'My/Decorator',
'decorator');
$subSubForm->setElementFilters(array('StringTrim'));
$subSubForm->addElement(new Zend_Form_Element_Text(array('name'=>'street',
...)));
$subSubForm->addElement(new Zend_Form_Element_Text(array('name'=>'city,
...)));
$subSubForm->addElement(new Zend_Form_Element_Text(array('name'=>'zip_code',
...)));
$subSubForm->setElementDecorators(array('MyElementDecorator'));
$subForm->addSubForm($subSubForm);
$subForm->setSubFormDecorators(array('MySubFormDecoratorForDivContainer'));
// <-- Address =============================

$subForm->setElementDecorators(array('MyElementDecorator'));
$form->addSubForm($subForm);
$form->setSubFormDecorators(array('MySubFormDecoratorForDivContainer'));
// <-- Person details =============================

$form->setElementDecorators(array('MyElementDecorator'));

I have to set decorators and element filters for every subform separately.
If I can use nested display groups, I would do this:

$form = new Zend_Form(array('method'=>'post'));
$form->setElementPrefixPath('My_Decorator', 'My/Decorator', 'decorator');
$form->setElementFilters(array('StringTrim'));
$form->addElement(new Zend_Form_Element_Text(array('name'=>'person_name',
...)));
$form->addElement(new Zend_Form_Element_Button(array('name'=>'show_details',
...)));
$form->addElement(new Zend_Form_Element_Text(array('name'=>'age', ...)));
$form->addElement(new
Zend_Form_Element_Text(array('name'=>'favourite_color', ...)));
$form->addElement(new
Zend_Form_Element_Text(array('name'=>'favourite_movie', ...)));
$form->addElement(new Zend_Form_Element_Button(array('name'=>'show_address',
...)));
$form->addElement(new Zend_Form_Element_Text(array('name'=>'street', ...)));
$form->addElement(new Zend_Form_Element_Text(array('name'=>'city, ...)));
$form->addElement(new Zend_Form_Element_Text(array('name'=>'zip_code',
...)));
$form->setElementDecorators(array('MyElementDecorator'));
$form->addDisplayGroup(array('street','city','zip_code'), 'address');

// as last "element" I would use previously defined display group "address"
$form->addDisplayGroup(array('age','favourite_color','favourite_movie','show_address','address'),
'details');

$form->setElementDecorators(array('MyElementDecorator'));

I don't want to use display groups to "logically" separate elements like on
multi page form. I just need to separate them "visually", which is exactly
purpose of display groups.
-- 
View this message in context: 
http://www.nabble.com/Zend_Form-feature-request---nested-display-groups-tp16572736p16580804.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to