Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Choosing a Catalyst form widget

by mattr (Curate)
on Apr 17, 2007 at 07:15 UTC ( #610473=perlquestion: print w/ replies, xml ) Need Help??
mattr has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks, I've got a Catalyst application that I started building at one time with HTML::Widget. However with a change in project author it is now deprecated with HTML::FormFu in the works as a replacement (in svn and described here, based in part on HTML::Widget and discussion going on in the H::W mailing list). (A Catalyst controller exists for it too). FormFu seems maybe alpha or beta quality (API changing) but bugs show up as they did with H::W.

When I tried to copy some code to make a new form using H::W the as_xml() function outputted all the form elements jammed into one line which is discouraging.. I think I had this problem once before too but even if I solve it, I remember H::W was not all that easy, it was tough to extend and there was this container kludge that didn't work for me. I backed off the mailing list about when radio button grouping was being discussed.

Now I have to build an admin interface with, and since I found H::W hard to use as well, I am looking once again at Catalyst::Controller::FormBuilder (based on CGI::FormBuilder). It has YAML-like syntax which FormFu also seems to be aiming towards.

If anybody has experience/recommendations they would be much appreciated. Constraint checking, validation and printing of errors are really icing on top, mainly it has to be quick and easy to make forms, repopulate the form, and if possible link to DBIx::Class in Catalyst to some extent. It seems H::W requires too much code (hence the YAML development I presume). How do you like FormBuilder, especially with Catalyst / DBIx::Class ? Anybody using FormFu and think it is best? Each form will be for a number of fields from a given class with some other elements possibly from other classes.

Comment on Choosing a Catalyst form widget
Re: Choosing a Catalyst form widget
by Anonymous Monk on Apr 17, 2007 at 13:24 UTC
Re: Choosing a Catalyst form widget
by phaylon (Curate) on Apr 17, 2007 at 13:34 UTC

    Disclaimer: This is all just IMHO and personal experiences. Other solutions might be more suitable for other environments.

    I have used HTML-Widget in the past, but I was always concerned with the fact that my controller defines the interface. I'm now using a self made controller base class doing configurable CRUD (not auto-detected). This is essentially it:

    • The form is organised and built with CGI-FormBuilder
    • The validation is done with Data-FormValidator
    • The controller base class reads its configuration as well as the fields from a YAML file that is loaded by the controller itself, since the YAML like source file for FB looks like YAML, but isn't really.
    • The controller also does the I18N
    • I don't use FB's native rendering facility, but walk the configured fields in a custom Template-Toolkit file that applies more general stylesheets, AJAX hooks, error and success messages.

    HTH, phaylon

    PS: I use DBIx::Class exclusively these days, at least for non-legacy projects.


    Ordinary morality is for ordinary people. -- Aleister Crowley
      Thanks. I started trying Catalyst::Controller::FormBuilder. I was stunned at how the YAML file suddenly made this beautiful form appear, with a JavaScript error message popping up; that alone is worth it perhaps. However I think the docs are a bit lacking, or maybe my first use of it is not one that is intended (first is a static form not based on an object in the database). Also I can't get css to target the form correctly.. Also I'm not quite sure if it is possible to get C::C::FB to render the form contents without editable fields, like a confirmation page, though it is not a deal-breaker. Probably rolling my own template would solve some of these issues..

      Also thanks for the tip, I didn't realize it isn't really YAML they're using, though they do say "essentially YAML".

      Also I found the pod code doesn't work for the simple static form I am making now that does not depend on the database; I think the edit() subroutine is not supposed to be used in this case perhaps. Just display cyclically with view() and then forward to save(). That is, the /edit url makes no form show, while the /view url displays an editable table. Perhaps edit() is meant to only work with a database object i.e. edit book id 5 with /edit/5, like in the CRUD tutorial.

      I'll keep at it, but I'm a bit worried that the /view url is showing an editable form. I'd think /view should only display existing data not as an input form at all... but if so then will have to roll my own confirmation page template I suppose. Hmm, maybe I need to make a dummy module to site in the DB directory that holds my DBIx::Class? I didn't make this one using the catalyst_create.pl script, maybe this is the problem?

      UPDATE: Successfully made a static form with Catalyst::Controller::FormBuilder. Only required defining fields in edit.fb, creating /view and /save subroutines, and creating templates for /view (which is about 1 line), /save (a for loop with table rows of field.label and field.value), and /error (dupe user name, etc. a stashed message). I think I'll see how this works out for the next stage of my project, too.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://610473]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2014-04-20 04:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls