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