-- Katulus <[EMAIL PROTECTED]> wrote
(on Wednesday, 09 April 2008, 12:03 AM -0700):
> 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).
> >
> You probably don't understand exactly what I want. Take this form:
<snip>
> 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'));
<snip>
And now we get to the meat of the problem:
> I have to set decorators and element filters for every subform separately.
I still content that Display Groups are the incorrect place to do this;
what you are doing is, quite simply, logical grouping (an action by the
user determines what group of elements to show). That said, it's
obvious that there's some capabilities you need that Zend_Form does not
currently support: the ability for setElement*() to affect *sub forms*.
This would allow you to call setElementPrefixPath, setElementFilters,
and setElementDecorators *once*, on the parent form, and have it
propagate to all elements in all sub forms. I think this is a reasonable
request to make.
So, if you'd be so kind, could you place an issue in the tracker for
this?
In the meantime, I'd suggest creating your own Zend_Form subclass that
overrides these methods to not only iterate over elements, but also sub
forms (let me know if you need help with this). The workflow at form
creation would then be:
* create elements
* create sub forms and their elements
* call the appropriate setElement*() methods
--
Matthew Weier O'Phinney
Software Architect | [EMAIL PROTECTED]
Zend - The PHP Company | http://www.zend.com/