Debian Codegraph @

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

raw
1 package HTML::FormHandler::Widget::Field::Checkbox;
2 # ABSTRACT: HTML attributes field role
3 $HTML::FormHandler::Widget::Field::Checkbox::VERSION = '0.410002';
4 use Moose::Role;
5 use namespace::autoclean;
6 use HTML::FormHandler::Render::Util ('process_attrs');
7
8
9 sub render_element {
10 my ( $self, $result ) = @_;
11 $result ||= $self->result;
12
13 my $checkbox_value = $self->checkbox_value;
14 my $output = '<input type="checkbox" name="'
15 . $self->html_name . '" id="' . $self->id . '" value="'
16 . $self->html_filter($checkbox_value) . '"';
17 $output .= ' checked="checked"'
18 if $result->fif eq $checkbox_value;
19 $output .= process_attrs($self->element_attributes($result));
20 $output .= ' />';
21 return $output;
22 }
23
24 sub render {
25 my ( $self, $result ) = @_;
26 $result ||= $self->result;
27 die "No result for form field '" . $self->full_name . "'. Field may be inactive." unless $result;
28 my $output = $self->render_element( $result );
29 return $self->wrap_field( $result, $output );
30 }
31
32 1;
33
34 __END__
35
36 =pod
37
38 =encoding UTF-8
39
40 =head1 NAME
41
42 HTML::FormHandler::Widget::Field::Checkbox - HTML attributes field role
43
44 =head1 VERSION
45
46 version 0.410002
47
48 =head1 SYNOPSIS
49
50 Checkbox field renderer
51
52 =head1 AUTHOR
53
54 FormHandler Contributors - see HTML::FormHandler
55
56 =head1 COPYRIGHT AND LICENSE
57
58 This software is copyright (c) 2017 by Gerda Shank.
59
60 This is free software; you can redistribute it and/or modify it under
61 the same terms as the Perl 5 programming language system itself.
62
63 =cut