HTML::FormHandler::Manual::RenderingCookbook(3pm)

HTML::FormHandler::Manual::RenderingCookbook3pm

Rendering recipes

Usage

Collection of rendering recipes

Version

version 0.40068

Recipes

Custom renderer, custom attributes

You want to be able to specify the attributes that are rendered in the 'td' tag of the table renderer...

First make your own copy of 'HTML::FormHandler::Widget::Wrapper::Table, in your own name space, and specify that name space in the 'widget_name_space' for the form.

Change this line in the Table wrapper:

    $output .= '<td>' . $self->do_render_label($result) . '</td>';

to this:

    my $td_attr = process_attrs($self->get_tag('td_attr') || {} );
    $output .= "<td$td_attr>" . $self->do_render_label($result) . '</td>';

Now you can specify the attributes for the 'td' tag on a field:

    has_field 'foo' => ( tags => { td_attr => { class => ['emph', 'label'] } } );

Render a collection of checkboxes like a checkbox group

Add a 'required' class to labels

Create a custom widget wrapper:

    package MyApp::Form::Widget::Wrapper::CustomLabel;
    use Moose::Role;
    with 'HTML::FormHandler::Widget::Wrapper::Simple';
    sub render_label {
        my ($self) = @_;
        return '<label class="label' . ($self->required ?
            ' required' : '') .  '" for="' . $self->id . '">' .
                 $self->html_filter($self->loc_label) . ':
            </label>';
    }

Or enable html5 output which adds a 'required' attribute.

Or use the 'html_attributes' callback:

    <in a form>
    sub html_attributes {
        my ( $self, $field, $type, $attr ) = @_;
        push @{$attr->{class}}, 'required'
            if ( $type eq 'label' && $field->required );
    }

Releases

6 releases since Debian 8 (Jessie); the text changed 3 times.

  1. 8
  2. 9
  3. 10–11
  4. 12–13

Author

FormHandler Contributors - see HTML::FormHandler

From libhtml-formhandler-perl 0.40068-2 in Debian 13 (Trixie). Parsed by carta from the page's man source.