[Html-widget] Rails-like form helpers - RFC for a new module
Zbigniew Lukasiak
zzbbyy at gmail.com
Fri Oct 6 17:41:55 CEST 2006
Hi,
I think the easiest way to start with this would be to try InstantCRUD
to generated the config.
I need to check if it is compatible with schema names composed of 3
parts (Schema::Db::Genders) I only checked it with 2 part names (like
DBSchema::Genders).
But see inline for comments:
On 10/6/06, John Napiorkowski <jjn1056 at yahoo.com> wrote:
> 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 $schema = $c->model('db');
I need the schema not the ResultSet. But now I think than perhaps I
should change that - your way seems a bit more intuitive.
> my $member = $members->find({member_id=>$id});
>
> my $conf = {
^ should be [ {
The config is a list of hashes.
>
> widget_element => ['Textfield'],
>
> name => 'name',
> label => 'User Name',
>
> constraints => [
>
> {
> constraint => 'Length',
> max => 64
> },
> {
> constraint => 'All',
> message => 'Required Field',
> },
> ],
} {
I assume here starts the next 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 )
$conf, $schema, 'Members', $member )
It needs the class (the item is optional so I cannot deduce the class
from it) - it is needed to get values for Selects.
I make a mental note to change 'Tag' to some variable there.
>
> 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
>
> _______________________________________________
> Html-widget mailing list
> Html-widget at lists.rawmode.org
> http://lists.rawmode.org/cgi-bin/mailman/listinfo/html-widget
>
--
Zbigniew Lukasiak
http://brudnopis.blogspot.com/
More information about the Html-widget
mailing list