[Catalyst] Rails-like form helpers
Zbigniew Lukasiak
zzbbyy at gmail.com
Mon Oct 16 10:41:33 CEST 2006
I was thinking a bit about this:
> in HTML::Widget you decide how you want your form
> controls to look in the model class, and in Rails you do it in the
> template
The standard answer to that is that the looks should be defined in the
CSS, but actually I don't buy that argument. It is good for the start
but then there are too many things that you need eventually to tweak
about the HTML. So eventually you start replacing more and more of
the generated HTML with the templates and in the end you would use
only the validation part of HTML::Widget.
This is very similar to the scaffolding idea and I think HTML::Widget
should support this process. Now we can generate the whole form by
HTML::Widget or use only the validation part, with the iteration over
the elements we can generate the elements but not the whole form and
at the last step we can have the whole HTML in the templates and use
only the validation part of HTML::Widget. We can add yet another
intermediate step by delaying the declaration of a input type to the
call in the templates. Something like:
In controller: my $el = $w->element('age'); $el->constraint( ....
In template: [% w.render_element('age, 'Textfield') %]
--
Zbyszek
- but than this would leave only the validation part in the HTML::Widget
On 10/13/06, Jon Warbrick <jw35 at cam.ac.uk> wrote:
> Sorry, I've been a bit slow replying to your questions :-)
>
> On Thu, 21 Sep 2006, Zbigniew Lukasiak wrote:
>
> > I don't know if I grap the idea of the helpers in full - could you explain
> > their functions here in short? For me it looks like they just create form
> > elements just like the $w->element('...', '...') does.
>
> Yes, that's about it. They are just shortcuts for use in templates to
> create form elements, except that
>
> 1) They deal with the stickiness/defaulting for you; and
>
> 2) They know how to name the elements to make updating the underlying
> model objects easier. So a text box for editing the 'name' field of a
> person record might be called 'person.name' (see below).
>
> 2) They know about the error flags that appear in the model objects
> following validation failure and so can adapt their behaviour
> accordingly (display with error flags, add error messages, etc).
>
> > There is something
> > also about using them for the updates - could you a bit elaborate on that?
>
> On form submission, these parameters are parsed into data structures in
> the equivalent of $req->parameters (so the edited name value from above
> might be in $req->parameters->{person}->{name}). The huge value of this is
> that the model objects can directly accept these structures for creation
> or update, e.g.
>
> $c->model('Person')->update($req->parameters->{person});
>
> > HTML::Widget also works on the update side - at least can check the
> > constraints, but it does not set values of an object - do the RoR helpers?
>
> A lot of this functionality exists in HTML::Widget. The main difference
> seems to be that in HTML::Widget you decide how you want your form
> controls to look in the model class, and in Rails you do it in the
> template.
>
> Jon.
>
> --
> Jon Warbrick
> Web/News Development, Computing Service, University of Cambridge
>
> _______________________________________________
> List: Catalyst at lists.rawmode.org
> Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/[email protected]/
> Dev site: http://dev.catalyst.perl.org/
>
--
Zbigniew Lukasiak
http://brudnopis.blogspot.com/
More information about the Catalyst
mailing list