PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/HTML/FormHandler/Widget/Field/Checkbox.pm

http://github.com/gshank/html-formhandler
Perl | 37 lines | 28 code | 8 blank | 1 comment | 2 complexity | d411223775633b950b5314434f4a770a MD5 | raw file
 1package HTML::FormHandler::Widget::Field::Checkbox;
 2# ABSTRACT: HTML attributes field role
 3
 4use Moose::Role;
 5use namespace::autoclean;
 6use HTML::FormHandler::Render::Util ('process_attrs');
 7
 8=head1 SYNOPSIS
 9
10Checkbox field renderer
11
12=cut
13
14sub render_element {
15    my ( $self, $result ) = @_;
16    $result ||= $self->result;
17
18    my $checkbox_value = $self->checkbox_value;
19    my $output = '<input type="checkbox" name="'
20        . $self->html_name . '" id="' . $self->id . '" value="'
21        . $self->html_filter($checkbox_value) . '"';
22    $output .= ' checked="checked"'
23        if $result->fif eq $checkbox_value;
24    $output .= process_attrs($self->element_attributes($result));
25    $output .= ' />';
26    return $output;
27}
28
29sub render {
30    my ( $self, $result ) = @_;
31    $result ||= $self->result;
32    die "No result for form field '" . $self->full_name . "'. Field may be inactive." unless $result;
33    my $output = $self->render_element( $result );
34    return $self->wrap_field( $result, $output );
35}
36
371;