[Html-widget] Rails-like form helpers - RFC for a new module
John Napiorkowski
jjn1056 at yahoo.com
Fri Oct 6 17:24:27 CEST 2006
Hi,
I'd like to give this a shot but having some trouble
fully grasping all the config setting. Let's say I
have a relatively simple case, a table like so:
Members
- member_id (PK)
- gender_id (FK)
- name
Genders
- gender_id (PK)
- name
Okay, and assuming I create some DBIx schemas for
these under:
Schema::Db::Members
Schema::Db::Genders
With the correct 'belongs_to' and 'has_many'
relationships between the two tables.
-- For members you can say ->gender to resolve the
gender object so you can do things like
"$member->gender->name".
-- For genders you can say ->members to resolve all
the members of a given gender like so
"$gender->members".
Let's assume all the PK's are auto increment to make
things easier.
Now let's say I wanted to make a form from the Members
table that has the name which is required but limited
to 64 characters and a select input for the gender_id
field that would link up to the genders table.
I'd do (assume I'm in Catalyst for the moment and have
a standard DBIx Schema model)
my $members = $c->model('db:members');
my $member = $members->find({member_id=>$id});
my $conf = {
widget_element => ['Textfield'],
name => 'name',
label => 'User Name',
constraints => [
{
constraint => 'Length',
max => 64
},
{
constraint => 'All',
message => 'Required Field',
},
],
widget_element => ['Select'],
name => 'gender_id',
label => 'Choose Your Gender',
bridge_rel => 'gender',
};
my $widget = HTML::Widget::DBIC->create_from_config(
$conf, $members, 'Tag', $member );
I'm sure I got this wrong (since it doesn't work :) ).
Where am I going wrong?
--John
--- Zbigniew Lukasiak <zzbbyy at gmail.com> wrote:
> I've just uploaded InstantCRUD version 0.0.17 to
> CPAN. It includes
> this new HTML::Widget::DBIC module.
> I am waiting for comments.
>
> --
> Zbyszek
>
> On 10/2/06, Zbigniew Lukasiak <zzbbyy at gmail.com>
> wrote:
> > I don't know but I don't like to add interface
> methods to the model - it
> > just does not feel right to me. So
> DBIx::Class::HTMLWidget does not work
> > for me.
> >
> > --
> > Zbyszek
> >
> > On 10/2/06, Ash Berlin <ash at cpan.org> wrote:
> > > Are you aware that there is a
> DBIx::Class::HTMLWidget module?
> > >
> > > Perhaps it would be an idea to make changes to
> that rather than create a
> > > new module - since currently it does almost
> nothing.
> > >
> > > Ash
> > >
> >
> >
> > --
> > Zbigniew Lukasiak
> > http://brudnopis.blogspot.com/
>
>
> --
> Zbigniew Lukasiak
> http://brudnopis.blogspot.com/
>
> _______________________________________________
> Html-widget mailing list
> Html-widget at lists.rawmode.org
>
http://lists.rawmode.org/cgi-bin/mailman/listinfo/html-widget
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the Html-widget
mailing list