1package HTML::FormHandler::Manual::RenderingCookbook;
2# ABSTRACT: rendering recipes
3
4__END__
5
6=pod
7
8=encoding UTF-8
9
10=head1 NAME
11
12HTML::FormHandler::Manual::RenderingCookbook - rendering recipes
13
14=head1 VERSION
15
16version 0.40068
17
18=head1 SYNOPSIS
19
20Collection of rendering recipes
21
22=head1 NAME
23
24HTML::FormHandler::Manual::Rendering::Cookbook
25
26=head1 Recipes
27
28=head2 Custom renderer, custom attributes
29
30You want to be able to specify the attributes that are rendered in the 'td' tag
31of the table renderer...
32
33First make your own copy of 'HTML::FormHandler::Widget::Wrapper::Table, in your
34own name space, and specify that name space in the 'widget_name_space' for the
35form.
36
37Change this line in the Table wrapper:
38
39    $output .= '<td>' . $self->do_render_label($result) . '</td>';
40
41to this:
42
43    my $td_attr = process_attrs($self->get_tag('td_attr') || {} );
44    $output .= "<td$td_attr>" . $self->do_render_label($result) . '</td>';
45
46Now you can specify the attributes for the 'td' tag on a field:
47
48    has_field 'foo' => ( tags => { td_attr => { class => ['emph', 'label'] } } );
49
50=head2 Render a collection of checkboxes like a checkbox group
51
52=head2 Add a 'required' class to labels
53
54Create a custom widget wrapper:
55
56    package MyApp::Form::Widget::Wrapper::CustomLabel;
57
58    use Moose::Role;
59    with 'HTML::FormHandler::Widget::Wrapper::Simple';
60
61    sub render_label {
62        my ($self) = @_;
63        return '<label class="label' . ($self->required ?
64            ' required' : '') .  '" for="' . $self->id . '">' .
65                 $self->html_filter($self->loc_label) . ':
66            </label>';
67    }
68
69Or enable html5 output which adds a 'required' attribute.
70
71Or use the 'html_attributes' callback:
72
73    <in a form>
74    sub html_attributes {
75        my ( $self, $field, $type, $attr ) = @_;
76        push @{$attr->{class}}, 'required'
77            if ( $type eq 'label' && $field->required );
78    }
79
80=head1 AUTHOR
81
82FormHandler Contributors - see HTML::FormHandler
83
84=head1 COPYRIGHT AND LICENSE
85
86This software is copyright (c) 2017 by Gerda Shank.
87
88This is free software; you can redistribute it and/or modify it under
89the same terms as the Perl 5 programming language system itself.
90
91=cut
92