[html-formfu] Nested Parameters (was: DBIC-FormFu extension)

Mario Minati mario.minati at googlemail.com
Sun Sep 23 10:25:12 GMT 2007


On Wednesday 19 September 2007 12:16:01 Carl Franks wrote:
> On 19/09/2007, Mario Minati <mario.minati at googlemail.com> wrote:
> > On Wednesday 19 September 2007 11:02:47 Carl Franks wrote:
> > > On 18/09/2007, Mario Minati <mario.minati at googlemail.com> wrote:
> > > > If you have the following form fields:
> > > >     private_street
> > > >     private_city
> > > >     private_email
> > > >     office_street
> > > >     office_city
> > > >     office_email
> > > >
> > > > You most likely would like to save both datasets in same table:
> > > >     my $private = $user->new_related( 'data', { type => 'private' }
> > > > ); $private->populate_from_formfu( $form, { prefix_col => 'private_'
> > > > } ); my $office = $user->new_related( 'data', { type => 'office' } );
> > > > $office->populate_from_formfu( $form, { prefix_col => 'office_' } );
> > >
> > > I think a more elegant solution would be by adding support for
> > > 'nested' params, e.g.
> > >
> > > with the following input:
> > >     "private.street" => x
> > >     "private.city" => y
> > >     "private.email" => z
> > >
> > > $form->param('private') would return a hashref:
> > > {
> > >     street => x,
> > >     city => y,
> > >     email => z,
> > > }
> >
> > This idea is more general and useful.
> >
> > > (or use the alternative syntax, "private[street]", "private[city]",
> > > etc.)
> >
> > Can we get HTML problems with parameter names including '.' or '[]' (I
> > favour '.' as it would allow chaining.)
>
> There shouldn't be any problems, this approach is already used by
> CGI::Expand and Catalyst::Plugin::Params::Nested.
>
> (The idea was pinched from RoR, which uses it extensively)
>
> > > Then do something like:
> > >
> > >     $relationship->populate_from_formfu(
> > >         $form,
> > >         { param => 'private' } );
> > >
> > > Also, it's maybe not immediately helpful in this example, but I'd like
> > > to break out the logic from Element/Dojo/Repeatable.pm into a core
> > > Element/Repeatable.pm element.
> > > This could help with some relationships, as it would provide automatic
> > > handling of multiple fields by adding an increasing numerical suffix
> > > to the fieldname.
> >
> > Would you do a more deeply change in FormFu, like adding an additional
> > parameter to fieldset like
> > - fieldset
> >     my_parameters_belong_to: private
> >     elements:
> >       - type: Text
> >         name: just_name
> >
> > which will lead to 'private.just_name' in HTML code.
>
> Yes, this approach.
>
> Though I'd probably just name it:
>     nested: private

JFYI:
I'm starting on this now.

Greets,
Mario



More information about the HTML-FormFu mailing list