CountZero has asked for the wisdom of the Perl Monks concerning the following question:

Dear Brothers and Sisters in Perl,

I was updating my knowledge of Catalyst by running through the tutorial for the integration of HTML::FormHandler.

Next I was trying to layout the different HTML fields of the form in a nice way using CSS. I did find out after some searching how to add CSS-classes to the various fields, so that was OK.

Then I tried to add a <Legend> tag to the fieldset.

HTML::FormHandler through the HTML::FormHandler::Render::Simple renderer encloses all your fields in one single fieldset of the "main_fieldset" class, but adding a <Legend> tag to that fieldset got me stumped.

Does anyone of you have some experience with these modules and knows how to accomplish this?

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Replies are listed 'Best First'.
Re: HTML::FormHandler rendering
by Anonymous Monk on May 15, 2010 at 18:59 UTC
      Thank you. That is a nice trick.

      But I did go through the source code myself already and it indeed seems there is some way of adding a <legend> tag, but the question is how?

      What I have now is:

      package MyApp::Form::Book; use HTML::FormHandler::Moose; extends 'HTML::FormHandler::Model::DBIC'; use namespace::autoclean; has '+item_class' => ( default =>'Books' ); has '+name' => ( default => 'book_form' ); has_field 'title' => ( minlength => 5, maxlength => 40, required => 1, + css_class => 'my-css-class' ); has_field 'rating' => ( type => 'Integer', range_start => 1, range_end + => 5 ); has_field 'authors' => ( type => 'Multiple', label_column => 'last_nam +e', required => 1 ); has_field 'submit' => ( type => 'Submit', value => 'Submit' ); __PACKAGE__->meta->make_immutable; 1;
      And I have no clue how to add the legend tag.

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

        If you look at the files returned by rep, like t/render.t, you can see its through naming convention.

        Does that makes sense?

        From your example I can't tell what you want to become legend/fieldset. If you could explain that, then it might become clear if HTML::FormHandler needs patching, or if you need to create your own renderer or something else :)

        FWIW, fieldset/legend doesn't look all that useful to me

Re: HTML::FormHandler rendering
by Khen1950fx (Canon) on May 16, 2010 at 04:14 UTC
    I read through the documentation, the manuals, and the source. I couldn't find any mention of legend. From my vantage point, I think that FormHandler will ignore legend, regardless of whether you try to enter it or not:). I tried entering legend with this script, but no luck.
    #!/usr/bin/perl use strict; use warnings; use HTML::FormHandler::Moose; extends 'HTML::FormHandler::Model::DBIC'; use namespace::autoclean; my $form = HTML::FormHandler->new( field_list => [ authors => { type => 'Multiple', label_column => 'last_name', legend => 'first_name', required => 1 } ] ); $form->process(); print my $rendered_form = $form->render;

      Moose imports strict and warnings for you, fyi.

      mtfnpy