Re: QF subforms: separate form template for the subform?
| From: | Justin Patrin | Date: | Thu, 08 Sep 2005 20:02:00 +0000 |
| Subject: | Re: QF subforms: separate form template for the subform? | ||
| References: | 1 2 3 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-20876@lists.php.net to get a copy of this message | ||
On 9/8/05, Ignatius Reilly <ignatius.reilly@free.fr> wrote:
> Justin Patrin wrote:
> > On 9/8/05, Ignatius Reilly <ignatius.reilly@free.fr> wrote:
> >
> >>I am experimenting with the *splendid* QF "subform" element.
> >>So far so good.
> >>
> >
> >
> > I'm glad you like it. I was pleased with how well it worked. It's also
> > just a delightful little hack. :-)
> >
> Going live soon... I'll inform you off ML
> >
> >>Now I want to assign a distinct form template to the subform, distinct
> >>from the main form's template, that is.
> >>I really mean here the form template, not the element template for the
> >>subform element (this can be set as usual, which is great)
> >>
> >>Has anybody an idea whether this can be done?
> >>At first sight it can not: it seems to me that there can be only one
> >>renderer instance, which can be assigned only one form template.
> >>Hopefully I have overlooked something...
> >>
> >>I am using HTML_QuickForm_Renderer_Default()
> >>
> >
> >
> > Well, you've run into the limitation I ended up building into the
> > SubForm element. For it to work "correctly" I had to hard-code in, as
> > it were, the use of the default template.
> >
> > I assume what you want to change is the <div> and <table>? The <form>
> > HTML is removed on line 136 (of course it is, nested forms in HTML
> > make no sense).
>
> Yes, I meant exactly that.
> At minimum one may want to pass class attributes to the div or table
> elements.
> A simple but ridiculously annoying thing:
> the default subform template (used in absence of an instantiated
> renderer for the QF form or page object) is
>
> {hidden}
> <table border="0">
> {content}
> </table>
>
> one would hope at least that the table element contains the attribute
> width="100%". It absence mangles things big time.
>
> You should be able to do this by altering the default
> > renderer with the template you want for the SubForm and then applying
> > a renderer object to the main form instead of letting it use the
> > default. Something like this:
> >
> > //create form(s) here
> > $default =& HTML_QuickForm::defaultRenderer();
> > $renderer = clone(HTML_QuickForm::defaultRenderer());
> > $default->setFormTemplate('form template for SubForms');
> > $renderer->setFormTemplate('form template for main form');
> > //you could also set any other templates you wish here
> > //$form is the main form
> > $form->accept($renderer);
> > echo $renderer->toHtml();
> >
> > Of course, this method only works if you want the same template
> > applied to all SubForms in your form. But, again, this is a limitation
> > due to how QF is laid out. This *could* be fixed by allowing a
> > renderer to be set for subforms, but since it inly supports the
> > default renderer (currently) this could lead to confusion.
> >
> In practice since only one "global" form template can be assigned to the
> renderer, one will preferably assign a form template to apply to the
> page form, not the subforms.
>
> Therefore another mechanism is needed.
> How about passing the subform template as an optional parameter to the
> subform constructor?
>
> function HTML_QuickForm_SubForm($name=null, $label=null, $form=null,
> $tpl=null)
>
> Just a shot in the dark...
>
I'm sorry, I'm not following. Did you try my example code? The
solution I gave you allows you to specify the renderer for your main
form while still editing the "default" renderer instance for the
subform.
The renderer semantics in QuickForm are a bit confusing. You can edit
the global instance of the renderer, which alters the renderer for
every form you output, or you can specify a renderer with accept (as
my code did). I know for sure that the code I sent you will allow you
to use a different renderer for your main form than for the subforms.
Please look over it again.
--
Justin Patrin