| 1 |
package HTML::FormHandler::Widget::Form::Table; |
| 2 |
# ABSTRACT: render a form with a table layout |
| 3 |
$HTML::FormHandler::Widget::Form::Table::VERSION = '0.410002'; |
| 4 |
use Moose::Role; |
| 5 |
with 'HTML::FormHandler::Widget::Form::Simple' => |
| 6 |
{ -excludes => [ 'render_start', 'render_end', 'render_form_errors' ] }; |
| 7 |
use HTML::FormHandler::Render::Util ('process_attrs'); |
| 8 |
use HTML::Entities qw( encode_entities ); |
| 9 |
|
| 10 |
|
| 11 |
sub render_start { |
| 12 |
my ( $self, $result ) = @_; |
| 13 |
$result ||= $self->result; |
| 14 |
my $fattrs = process_attrs($self->attributes($result)); |
| 15 |
my $wattrs = process_attrs($self->form_wrapper_attributes($result)); |
| 16 |
return qq{<form$fattrs><table$wattrs>\n}; |
| 17 |
} |
| 18 |
|
| 19 |
sub render_form_errors { |
| 20 |
my ( $self, $result ) = @_; |
| 21 |
|
| 22 |
return '' unless $result->has_form_errors; |
| 23 |
my $output = "\n<tr class=\"form_errors\"><td colspan=\"2\">"; |
| 24 |
$output .= qq{\n<span class="error_message">$_</span>} |
| 25 |
for map { encode_entities($_) } $result->all_form_errors; |
| 26 |
$output .= "\n</td></tr>"; |
| 27 |
return $output; |
| 28 |
} |
| 29 |
|
| 30 |
sub render_end { |
| 31 |
my $self = shift; |
| 32 |
my $output = "</table>\n"; |
| 33 |
$output .= "</form>\n"; |
| 34 |
return $output; |
| 35 |
} |
| 36 |
|
| 37 |
use namespace::autoclean; |
| 38 |
1; |
| 39 |
|
| 40 |
__END__ |
| 41 |
|
| 42 |
=pod |
| 43 |
|
| 44 |
=encoding UTF-8 |
| 45 |
|
| 46 |
=head1 NAME |
| 47 |
|
| 48 |
HTML::FormHandler::Widget::Form::Table - render a form with a table layout |
| 49 |
|
| 50 |
=head1 VERSION |
| 51 |
|
| 52 |
version 0.410002 |
| 53 |
|
| 54 |
=head1 SYNOPSIS |
| 55 |
|
| 56 |
Set in your form: |
| 57 |
|
| 58 |
has '+widget_form' => ( default => 'Table' ); |
| 59 |
|
| 60 |
Use in a template: |
| 61 |
|
| 62 |
[% form.render %] |
| 63 |
|
| 64 |
=head1 AUTHOR |
| 65 |
|
| 66 |
FormHandler Contributors - see HTML::FormHandler |
| 67 |
|
| 68 |
=head1 COPYRIGHT AND LICENSE |
| 69 |
|
| 70 |
This software is copyright (c) 2017 by Gerda Shank. |
| 71 |
|
| 72 |
This is free software; you can redistribute it and/or modify it under |
| 73 |
the same terms as the Perl 5 programming language system itself. |
| 74 |
|
| 75 |
=cut |