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.40068'; |
4
|
7
|
|
|
7
|
|
5580
|
use Moose::Role; |
|
7
|
|
|
|
|
21
|
|
|
7
|
|
|
|
|
514
|
|
5
|
7
|
|
|
7
|
|
39158
|
use namespace::autoclean; |
|
7
|
|
|
|
|
20
|
|
|
7
|
|
|
|
|
82
|
|
6
|
7
|
|
|
7
|
|
614
|
use HTML::FormHandler::Render::Util ('process_attrs'); |
|
7
|
|
|
|
|
20
|
|
|
7
|
|
|
|
|
410
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub render { |
10
|
10
|
|
|
10
|
0
|
41
|
my ( $self, $result ) = @_; |
11
|
10
|
|
66
|
|
|
268
|
$result ||= $self->result; |
12
|
10
|
50
|
|
|
|
37
|
die "No result for form field '" . $self->full_name . "'. Field may be inactive." unless $result; |
13
|
10
|
|
|
|
|
65
|
my $output = $self->render_element( $result ); |
14
|
10
|
|
|
|
|
65
|
return $self->wrap_field( $result, $output ); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub render_element { |
18
|
10
|
|
|
10
|
0
|
34
|
my ( $self, $result ) = @_; |
19
|
10
|
|
33
|
|
|
52
|
$result ||= $self->result; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# loop through options |
23
|
10
|
|
|
|
|
28
|
my $output = ''; |
24
|
10
|
|
|
|
|
29
|
foreach my $option ( @{ $self->{options} } ) { |
|
10
|
|
|
|
|
45
|
|
25
|
30
|
100
|
|
|
|
116
|
if ( my $label = $option->{group} ) { |
26
|
5
|
50
|
|
|
|
165
|
$label = $self->_localize( $label ) if $self->localize_labels; |
27
|
5
|
|
100
|
|
|
30
|
my $attr = $option->{attributes} || {}; |
28
|
5
|
|
|
|
|
26
|
my $attr_str = process_attrs($attr); |
29
|
5
|
|
100
|
|
|
27
|
my $lattr = $option->{label_attributes} || {}; |
30
|
5
|
|
|
|
|
17
|
my $lattr_str= process_attrs($lattr); |
31
|
5
|
|
|
|
|
21
|
$output .= qq{\n<div$attr_str><label$lattr_str>$label</label>}; |
32
|
5
|
|
|
|
|
12
|
foreach my $group_opt ( @{ $option->{options} } ) { |
|
5
|
|
|
|
|
16
|
|
33
|
15
|
|
|
|
|
46
|
$output .= $self->render_option( $group_opt, $result ); |
34
|
|
|
|
|
|
|
} |
35
|
5
|
|
|
|
|
22
|
$output .= qq{\n</div>}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
else { |
38
|
25
|
|
|
|
|
107
|
$output .= $self->render_option( $option, $result ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
10
|
|
|
|
|
410
|
$self->reset_options_index; |
42
|
10
|
|
|
|
|
29
|
return $output; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub render_option { |
46
|
40
|
|
|
40
|
0
|
95
|
my ( $self, $option, $result ) = @_; |
47
|
40
|
|
33
|
|
|
120
|
$result ||= $self->result; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# get existing values |
50
|
40
|
|
|
|
|
166
|
my $fif = $result->fif; |
51
|
40
|
|
|
|
|
89
|
my %fif_lookup; |
52
|
40
|
50
|
|
|
|
1052
|
@fif_lookup{@$fif} = () if $self->multiple; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# create option label attributes |
55
|
40
|
|
50
|
|
|
242
|
my $lattr = $option->{label_attributes} || {}; |
56
|
40
|
|
|
|
|
86
|
push @{ $lattr->{class} }, 'checkbox'; |
|
40
|
|
|
|
|
163
|
|
57
|
40
|
100
|
|
|
|
178
|
if ( $self->get_tag('inline') ) { |
58
|
9
|
|
|
|
|
21
|
my $class = 'inline'; |
59
|
9
|
100
|
|
|
|
30
|
$class = 'checkbox-inline' if $self->has_flag('is_b3'); |
60
|
9
|
|
|
|
|
19
|
push @{ $lattr->{class} }, $class; |
|
9
|
|
|
|
|
22
|
|
61
|
|
|
|
|
|
|
} |
62
|
40
|
|
|
|
|
152
|
my $lattr_str = process_attrs( $lattr ); |
63
|
40
|
|
|
|
|
1046
|
my $id = $self->id . '.' . $self->options_index; |
64
|
40
|
|
|
|
|
137
|
my $output .= qq{\n<label$lattr_str for="$id">}; |
65
|
40
|
|
|
|
|
95
|
my $value = $option->{value}; |
66
|
40
|
|
|
|
|
91
|
$output .= qq{\n<input type="checkbox"}; |
67
|
40
|
|
|
|
|
1273
|
$output .= qq{ value="} . $self->html_filter($value) . '"'; |
68
|
40
|
|
|
|
|
981
|
$output .= qq{ name="} . $self->html_name . '"'; |
69
|
40
|
|
|
|
|
99
|
$output .= qq{ id="$id"}; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# handle option attributes |
72
|
40
|
|
50
|
|
|
202
|
my $attr = $option->{attributes} || {}; |
73
|
40
|
0
|
33
|
|
|
126
|
if( defined $option->{disabled} && $option->{disabled} ) { |
74
|
0
|
|
|
|
|
0
|
$attr->{disabled} = 'disabled'; |
75
|
|
|
|
|
|
|
} |
76
|
40
|
100
|
66
|
|
|
1124
|
if ( defined $fif && |
|
|
|
33
|
|
|
|
|
77
|
|
|
|
|
|
|
( ( $self->multiple && exists $fif_lookup{$value} ) || |
78
|
|
|
|
|
|
|
( $fif eq $value ) ) ) { |
79
|
4
|
|
|
|
|
13
|
$attr->{checked} = 'checked'; |
80
|
|
|
|
|
|
|
} |
81
|
40
|
|
|
|
|
136
|
$output .= process_attrs($attr); |
82
|
40
|
|
|
|
|
84
|
$output .= " />\n"; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# handle label |
85
|
40
|
|
|
|
|
94
|
my $label = $option->{label}; |
86
|
40
|
50
|
|
|
|
1118
|
$label = $self->_localize($label) if $self->localize_labels; |
87
|
40
|
|
|
|
|
1192
|
$output .= $self->html_filter($label); |
88
|
40
|
|
|
|
|
87
|
$output .= "\n</label>"; |
89
|
40
|
|
|
|
|
1429
|
$self->inc_options_index; |
90
|
|
|
|
|
|
|
|
91
|
40
|
100
|
|
|
|
131
|
if ($self->get_tag('checkbox_element_wrapper')) { |
92
|
3
|
|
|
|
|
10
|
$output = qq{<div class="checkbox">$output</div>}; |
93
|
|
|
|
|
|
|
} |
94
|
40
|
|
|
|
|
232
|
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.40068 |
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) 2017 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 |