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