[html-formfu] defaults_from_model not filling a nested Checkboxgroup

Jonas Alves jonas.alves at gmail.com
Sun Dec 16 19:56:20 GMT 2007


On Dec 16, 2007 2:58 PM, Jonas Alves <jonas.alves at gmail.com> wrote:

>
>
> On Dec 15, 2007 5:22 PM, Carl Franks <fireartist at gmail.com> wrote:
>
> > On 15/12/2007, Jonas Alves <jonas.alves at gmail.com> wrote:
> > > Hi Guys,
> > > I have a form with an element like this:
> > >
> > >           - type: Block
> > >             tag: ~
> > >             nested_name: area_rel
> > >             elements:
> > >               - type: Checkboxgroup
> > >                 name: area_id
> > >                 options: [ ... ]
> > >                 constraints: [ AutoSet ]
> > >
> > > area_rel is a many_to_many relationship defined in my model.
> > >
> > >
> > > And defaults_from_model fails to fill it. Am I doing something wrong,
> > or
> > > this is not supported yet?
> >
> > Hi Jonas,
> >
> > http://search.cpan.org/~cfranks/HTML-FormFu-0.02002/lib/HTML/FormFu/Mod=
el/DBIC.pm#many_to_many_selection
> >
> > <http://search.cpan.org/%7Ecfranks/HTML-FormFu-0.02002/lib/HTML/FormFu/=
Model/DBIC.pm#many_to_many_selection>
> >
> > You don't need the Block for that:
> >
> >    type: Checkboxgroup
> >    name: area_rel
> >
> > If area_id is the PK, it'll pick that up automatically, otherwise you
> > can be explicit:
> >
> >    db: { default_column: area_id }
> >
> > And this isn't documented yet because it may change, but with the
> > catalyst controller you can populate the Checkboxgroup from the db
> > like so:
> >
> >    type: Checkboxgroup
> >    name: area_rel
> >    db:
> >      model: MyModel
> >      label_col: area
> >
> > See the source of Element/_Group::process() for more details.
> >
> > Cheers,
> > Carl
> >
>
> Hi Carl,
> I can't make it work. The  Checkboxgroup is not being populated.
> Element/_Group::process is not being called at all.
>
> This is what I have in the config file:
>
>           - type: Checkboxgroup
>             name: area_rel
>             db:
>               model: DBIC::Area
>               label_col: name
>             constraints: [ AutoSet ]
>
> The rels in DBIC::Campanha model:
>
> __PACKAGE__->has_many(
>     area_rel =3D> 'SMS::Schema::Result::AreaCampanha', 'campanha_id',
> );
> __PACKAGE__->many_to_many(areas =3D> 'area_rel', 'area_id',);
>
> # in my app:
>
> $form->defaults_from_model( $campanha_row );
>
> If I change the rel in the config to "name: areas" instead of "name:
> area_rel" I got this error:
>
> [error] DBIx::Class::Relationship::ManyToMany::__ANON__(): search_related:
> result source 'AreaCampanha' has no such relationship area_id at
> /Library/Perl/5.8.6/HTML/FormFu/Model/DBIC.pm line 186
>
>
> Do you have any idea what am I doing wrong?
>
> Thanks
> --
> Jonas
>

Hi Carl,
I wasn't using the Cat Controller, and wasn't calling the process method
before showing the form. That's why the radiogroup was empty. The other
error was a bad defined many_to_many rel. It's all working now. Thanks a
lot. :)

May I suggest that in the end of Element/_Group::process you add something
like this:

unshift @defaults, @{$self->_options || []};

That way you can mix options defined in the config with the ones fetched
from the model.
And maybe one param to tell if the options should go in the beginning or in
the end.

Cheers,
-- =

Jonas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/html-formfu/attachments/20071216/3d=
415280/attachment-0001.htm


More information about the HTML-FormFu mailing list