line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormHandler::Widget::Field::CheckboxGroup; |
2
|
|
|
|
|
|
|
# ABSTRACT: checkbox group field role |
3
|
|
|
|
|
|
|
$HTML::FormHandler::Widget::Field::CheckboxGroup::VERSION = '0.40067'; |
4
|
7
|
|
|
7
|
|
4873
|
use Moose::Role; |
|
7
|
|
|
|
|
11
|
|
|
7
|
|
|
|
|
62
|
|
5
|
7
|
|
|
7
|
|
25715
|
use namespace::autoclean; |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
67
|
|
6
|
7
|
|
|
7
|
|
490
|
use HTML::FormHandler::Render::Util ('process_attrs'); |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
61
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub render { |
10
|
10
|
|
|
10
|
0
|
20
|
my ( $self, $result ) = @_; |
11
|
10
|
|
66
|
|
|
242
|
$result ||= $self->result; |
12
|
10
|
50
|
|
|
|
29
|
die "No result for form field '" . $self->full_name . "'. Field may be inactive." unless $result; |
13
|
10
|
|
|
|
|
44
|
my $output = $self->render_element( $result ); |
14
|
10
|
|
|
|
|
56
|
return $self->wrap_field( $result, $output ); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub render_element { |
18
|
10
|
|
|
10
|
0
|
30
|
my ( $self, $result ) = @_; |
19
|
10
|
|
33
|
|
|
27
|
$result ||= $self->result; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# loop through options |
23
|
10
|
|
|
|
|
25
|
my $output = ''; |
24
|
10
|
|
|
|
|
15
|
foreach my $option ( @{ $self->{options} } ) { |
|
10
|
|
|
|
|
35
|
|
25
|
30
|
100
|
|
|
|
103
|
if ( my $label = $option->{group} ) { |
26
|
5
|
50
|
|
|
|
135
|
$label = $self->_localize( $label ) if $self->localize_labels; |
27
|
5
|
|
100
|
|
|
23
|
my $attr = $option->{attributes} || {}; |
28
|
5
|
|
|
|
|
15
|
my $attr_str = process_attrs($attr); |
29
|
5
|
|
100
|
|
|
20
|
my $lattr = $option->{label_attributes} || {}; |
30
|
5
|
|
|
|
|
10
|
my $lattr_str= process_attrs($lattr); |
31
|
5
|
|
|
|
|
13
|
$output .= qq{\n<div$attr_str><label$lattr_str>$label</label>}; |
32
|
5
|
|
|
|
|
6
|
foreach my $group_opt ( @{ $option->{options} } ) { |
|
5
|
|
|
|
|
11
|
|
33
|
15
|
|
|
|
|
24
|
$output .= $self->render_option( $group_opt, $result ); |
34
|
|
|
|
|
|
|
} |
35
|
5
|
|
|
|
|
13
|
$output .= qq{\n</div>}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
else { |
38
|
25
|
|
|
|
|
63
|
$output .= $self->render_option( $option, $result ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
10
|
|
|
|
|
379
|
$self->reset_options_index; |
42
|
10
|
|
|
|
|
22
|
return $output; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub render_option { |
46
|
40
|
|
|
40
|
0
|
44
|
my ( $self, $option, $result ) = @_; |
47
|
40
|
|
33
|
|
|
77
|
$result ||= $self->result; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# get existing values |
50
|
40
|
|
|
|
|
116
|
my $fif = $result->fif; |
51
|
40
|
|
|
|
|
44
|
my %fif_lookup; |
52
|
40
|
50
|
|
|
|
968
|
@fif_lookup{@$fif} = () if $self->multiple; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# create option label attributes |
55
|
40
|
|
50
|
|
|
153
|
my $lattr = $option->{label_attributes} || {}; |
56
|
40
|
|
|
|
|
42
|
push @{ $lattr->{class} }, 'checkbox'; |
|
40
|
|
|
|
|
95
|
|
57
|
40
|
100
|
|
|
|
121
|
if ( $self->get_tag('inline') ) { |
58
|
9
|
|
|
|
|
11
|
my $class = 'inline'; |
59
|
9
|
100
|
|
|
|
25
|
$class = 'checkbox-inline' if $self->has_flag('is_b3'); |
60
|
9
|
|
|
|
|
10
|
push @{ $lattr->{class} }, $class; |
|
9
|
|
|
|
|
18
|
|
61
|
|
|
|
|
|
|
} |
62
|
40
|
|
|
|
|
103
|
my $lattr_str = process_attrs( $lattr ); |
63
|
40
|
|
|
|
|
995
|
my $id = $self->id . '.' . $self->options_index; |
64
|
40
|
|
|
|
|
89
|
my $output .= qq{\n<label$lattr_str for="$id">}; |
65
|
40
|
|
|
|
|
66
|
my $value = $option->{value}; |
66
|
40
|
|
|
|
|
52
|
$output .= qq{\n<input type="checkbox"}; |
67
|
40
|
|
|
|
|
1212
|
$output .= qq{ value="} . $self->html_filter($value) . '"'; |
68
|
40
|
|
|
|
|
948
|
$output .= qq{ name="} . $self->html_name . '"'; |
69
|
40
|
|
|
|
|
60
|
$output .= qq{ id="$id"}; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# handle option attributes |
72
|
40
|
|
50
|
|
|
160
|
my $attr = $option->{attributes} || {}; |
73
|
40
|
0
|
33
|
|
|
82
|
if( defined $option->{disabled} && $option->{disabled} ) { |
74
|
0
|
|
|
|
|
0
|
$attr->{disabled} = 'disabled'; |
75
|
|
|
|
|
|
|
} |
76
|
40
|
100
|
66
|
|
|
1129
|
if ( defined $fif && |
|
|
|
33
|
|
|
|
|
77
|
|
|
|
|
|
|
( ( $self->multiple && exists $fif_lookup{$value} ) || |
78
|
|
|
|
|
|
|
( $fif eq $value ) ) ) { |
79
|
4
|
|
|
|
|
9
|
$attr->{checked} = 'checked'; |
80
|
|
|
|
|
|
|
} |
81
|
40
|
|
|
|
|
101
|
$output .= process_attrs($attr); |
82
|
40
|
|
|
|
|
59
|
$output .= " />\n"; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# handle label |
85
|
40
|
|
|
|
|
56
|
my $label = $option->{label}; |
86
|
40
|
50
|
|
|
|
1179
|
$label = $self->_localize($label) if $self->localize_labels; |
87
|
40
|
|
|
|
|
1174
|
$output .= $self->html_filter($label); |
88
|
40
|
|
|
|
|
49
|
$output .= "\n</label>"; |
89
|
40
|
|
|
|
|
1282
|
$self->inc_options_index; |
90
|
|
|
|
|
|
|
|
91
|
40
|
100
|
|
|
|
90
|
if ($self->get_tag('checkbox_element_wrapper')) { |
92
|
3
|
|
|
|
|
7
|
$output = qq{<div class="checkbox">$output</div>}; |
93
|
|
|
|
|
|
|
} |
94
|
40
|
|
|
|
|
185
|
return $output; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
__END__ |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=pod |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=encoding UTF-8 |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 NAME |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
HTML::FormHandler::Widget::Field::CheckboxGroup - checkbox group field role |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 VERSION |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
version 0.40067 |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 SYNOPSIS |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Checkbox group widget for rendering multiple selects. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Checkbox element label class is 'checkbox', plus 'inline' |
118
|
|
|
|
|
|
|
if the 'inline' tag is set. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Options hashrefs must have the keys 'value', and 'label'. |
121
|
|
|
|
|
|
|
They may have an 'attributes' hashref key. The 'checked' |
122
|
|
|
|
|
|
|
attribute should not be set in the options hashref. It should |
123
|
|
|
|
|
|
|
be set by supplying a default value or from params input. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
See L<HTML::FormHandler::Field::Select> for documentation on |
126
|
|
|
|
|
|
|
select fields and options. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 AUTHOR |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
FormHandler Contributors - see HTML::FormHandler |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
This software is copyright (c) 2016 by Gerda Shank. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
137
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=cut |