.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "HTML::FormHandler::Manual::RenderingCookbook 3pm" .TH HTML::FormHandler::Manual::RenderingCookbook 3pm "2022-03-25" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" HTML::FormHandler::Manual::RenderingCookbook \- rendering recipes .SH "VERSION" .IX Header "VERSION" version 0.40068 .SH "SYNOPSIS" .IX Header "SYNOPSIS" Collection of rendering recipes .SH "NAME" HTML::FormHandler::Manual::Rendering::Cookbook .SH "Recipes" .IX Header "Recipes" .SS "Custom renderer, custom attributes" .IX Subsection "Custom renderer, custom attributes" You want to be able to specify the attributes that are rendered in the 'td' tag of the table renderer... .PP 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. .PP Change this line in the Table wrapper: .PP .Vb 1 \& $output .= \*(Aq\*(Aq . $self\->do_render_label($result) . \*(Aq\*(Aq; .Ve .PP to this: .PP .Vb 2 \& my $td_attr = process_attrs($self\->get_tag(\*(Aqtd_attr\*(Aq) || {} ); \& $output .= "" . $self\->do_render_label($result) . \*(Aq\*(Aq; .Ve .PP Now you can specify the attributes for the 'td' tag on a field: .PP .Vb 1 \& has_field \*(Aqfoo\*(Aq => ( tags => { td_attr => { class => [\*(Aqemph\*(Aq, \*(Aqlabel\*(Aq] } } ); .Ve .SS "Render a collection of checkboxes like a checkbox group" .IX Subsection "Render a collection of checkboxes like a checkbox group" .SS "Add a 'required' class to labels" .IX Subsection "Add a 'required' class to labels" Create a custom widget wrapper: .PP .Vb 1 \& package MyApp::Form::Widget::Wrapper::CustomLabel; \& \& use Moose::Role; \& with \*(AqHTML::FormHandler::Widget::Wrapper::Simple\*(Aq; \& \& sub render_label { \& my ($self) = @_; \& return \*(Aq\*(Aq; \& } .Ve .PP Or enable html5 output which adds a 'required' attribute. .PP Or use the 'html_attributes' callback: .PP .Vb 6 \& \& sub html_attributes { \& my ( $self, $field, $type, $attr ) = @_; \& push @{$attr\->{class}}, \*(Aqrequired\*(Aq \& if ( $type eq \*(Aqlabel\*(Aq && $field\->required ); \& } .Ve .SH "AUTHOR" .IX Header "AUTHOR" FormHandler Contributors \- see HTML::FormHandler .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2017 by Gerda Shank. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.