PageRenderTime 51ms CodeModel.GetById 37ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/HTML/FormHandler/Widget/Form/Table.pm

http://github.com/gshank/html-formhandler
Perl | 49 lines | 35 code | 13 blank | 1 comment | 1 complexity | 47759fe34ea115e78efbf5fde65c4fae MD5 | raw file
 1package HTML::FormHandler::Widget::Form::Table;
 2# ABSTRACT: render a form with a table layout
 3
 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=head1 SYNOPSIS
10
11Set in your form:
12
13   has '+widget_form' => ( default => 'Table' );
14
15Use in a template:
16
17   [% form.render %]
18
19=cut
20
21sub render_start {
22    my ( $self, $result ) = @_;
23    $result ||= $self->result;
24    my $fattrs = process_attrs($self->attributes($result));
25    my $wattrs = process_attrs($self->form_wrapper_attributes($result));
26    return qq{<form$fattrs><table$wattrs>\n};
27}
28
29sub render_form_errors {
30    my ( $self, $result ) = @_;
31
32    return '' unless $result->has_form_errors;
33    my $output = "\n<tr class=\"form_errors\"><td colspan=\"2\">";
34    $output .= qq{\n<span class="error_message">$_</span>}
35        for $result->all_form_errors;
36    $output .= "\n</td></tr>";
37    return $output;
38}
39
40sub render_end {
41    my $self = shift;
42    my $output .= "</table>\n";
43    $output .= "</form>\n";
44    return $output;
45}
46
47use namespace::autoclean;
481;
49