line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormHandler::Widget::Field::HorizCheckboxGroup; |
2
|
|
|
|
|
|
|
# ABSTRACT: checkbox group field role |
3
|
|
|
|
|
|
|
$HTML::FormHandler::Widget::Field::HorizCheckboxGroup::VERSION = '0.40068'; |
4
|
1
|
|
|
1
|
|
720
|
use Moose::Role; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
11
|
|
5
|
1
|
|
|
1
|
|
4801
|
use namespace::autoclean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
6
|
1
|
|
|
1
|
|
69
|
use HTML::FormHandler::Render::Util ('process_attrs'); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub render { |
10
|
1
|
|
|
1
|
0
|
3
|
my ( $self, $result ) = @_; |
11
|
1
|
|
33
|
|
|
31
|
$result ||= $self->result; |
12
|
1
|
50
|
|
|
|
4
|
die "No result for form field '" . $self->full_name . "'. Field may be inactive." unless $result; |
13
|
1
|
|
|
|
|
5
|
my $output = $self->render_element( $result ); |
14
|
1
|
|
|
|
|
6
|
return $self->wrap_field( $result, $output ); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub render_element { |
18
|
1
|
|
|
1
|
0
|
3
|
my ( $self, $result ) = @_; |
19
|
1
|
|
33
|
|
|
3
|
$result ||= $self->result; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# loop through options |
23
|
1
|
|
|
|
|
4
|
my $output = ''; |
24
|
1
|
|
|
|
|
2
|
foreach my $option ( @{ $self->{options} } ) { |
|
1
|
|
|
|
|
3
|
|
25
|
4
|
50
|
|
|
|
11
|
if ( my $label = $option->{group} ) { |
26
|
0
|
0
|
|
|
|
0
|
$label = $self->_localize( $label ) if $self->localize_labels; |
27
|
0
|
|
0
|
|
|
0
|
my $attr = $option->{attributes} || {}; |
28
|
0
|
|
|
|
|
0
|
my $attr_str = process_attrs($attr); |
29
|
0
|
|
0
|
|
|
0
|
my $lattr = $option->{label_attributes} || {}; |
30
|
0
|
|
|
|
|
0
|
my $lattr_str= process_attrs($lattr); |
31
|
0
|
|
|
|
|
0
|
$output .= qq{\n<div$attr_str><label$lattr_str>$label</label>}; |
32
|
0
|
|
|
|
|
0
|
foreach my $group_opt ( @{ $option->{options} } ) { |
|
0
|
|
|
|
|
0
|
|
33
|
0
|
|
|
|
|
0
|
$output .= $self->render_option( $group_opt, $result ); |
34
|
|
|
|
|
|
|
} |
35
|
0
|
|
|
|
|
0
|
$output .= qq{\n</div>}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
else { |
38
|
4
|
|
|
|
|
13
|
$output .= $self->render_option( $option, $result ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
1
|
|
|
|
|
40
|
$self->reset_options_index; |
42
|
1
|
|
|
|
|
2
|
return $output; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub render_option { |
46
|
4
|
|
|
4
|
0
|
8
|
my ( $self, $option, $result ) = @_; |
47
|
4
|
|
33
|
|
|
11
|
$result ||= $self->result; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# get existing values |
50
|
4
|
|
|
|
|
14
|
my $fif = $result->fif; |
51
|
4
|
|
|
|
|
7
|
my %fif_lookup; |
52
|
4
|
50
|
|
|
|
103
|
@fif_lookup{@$fif} = () if $self->multiple; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# create option label attributes |
55
|
4
|
|
50
|
|
|
24
|
my $lattr = $option->{label_attributes} || {}; |
56
|
4
|
|
|
|
|
15
|
my $lattr_str = process_attrs( $lattr ); |
57
|
|
|
|
|
|
|
|
58
|
4
|
|
|
|
|
99
|
my $id = $self->id . '.' . $self->options_index; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# start wrapping div |
61
|
4
|
|
|
|
|
9
|
my $output = qq{<div class="checkbox">}; |
62
|
|
|
|
|
|
|
|
63
|
4
|
|
|
|
|
11
|
$output .= qq{\n<label$lattr_str for="$id">}; |
64
|
4
|
|
|
|
|
8
|
my $value = $option->{value}; |
65
|
4
|
|
|
|
|
9
|
$output .= qq{\n<input type="checkbox"}; |
66
|
4
|
|
|
|
|
125
|
$output .= qq{ value="} . $self->html_filter($value) . '"'; |
67
|
4
|
|
|
|
|
95
|
$output .= qq{ name="} . $self->html_name . '"'; |
68
|
4
|
|
|
|
|
9
|
$output .= qq{ id="$id"}; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# handle option attributes |
71
|
4
|
|
50
|
|
|
18
|
my $attr = $option->{attributes} || {}; |
72
|
4
|
0
|
33
|
|
|
13
|
if( defined $option->{disabled} && $option->{disabled} ) { |
73
|
0
|
|
|
|
|
0
|
$attr->{disabled} = 'disabled'; |
74
|
|
|
|
|
|
|
} |
75
|
4
|
50
|
33
|
|
|
110
|
if ( defined $fif && |
|
|
|
33
|
|
|
|
|
76
|
|
|
|
|
|
|
( ( $self->multiple && exists $fif_lookup{$value} ) || |
77
|
|
|
|
|
|
|
( $fif eq $value ) ) ) { |
78
|
0
|
|
|
|
|
0
|
$attr->{checked} = 'checked'; |
79
|
|
|
|
|
|
|
} |
80
|
4
|
|
|
|
|
13
|
$output .= process_attrs($attr); |
81
|
4
|
|
|
|
|
9
|
$output .= " />\n"; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# handle label |
84
|
4
|
|
|
|
|
9
|
my $label = $option->{label}; |
85
|
4
|
50
|
|
|
|
111
|
$label = $self->_localize($label) if $self->localize_labels; |
86
|
4
|
|
|
|
|
118
|
$output .= $self->html_filter($label); |
87
|
4
|
|
|
|
|
8
|
$output .= "\n</label>"; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# close wrapping div |
90
|
4
|
|
|
|
|
10
|
$output .= "\n</div>"; |
91
|
|
|
|
|
|
|
|
92
|
4
|
|
|
|
|
154
|
$self->inc_options_index; |
93
|
4
|
|
|
|
|
19
|
return $output; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=pod |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=encoding UTF-8 |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 NAME |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
HTML::FormHandler::Widget::Field::HorizCheckboxGroup - checkbox group field role |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 VERSION |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
version 0.40068 |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 SYNOPSIS |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Checkbox group widget for rendering multiple selects. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Wraps each checkbox in a div. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 AUTHOR |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
FormHandler Contributors - see HTML::FormHandler |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
This software is copyright (c) 2017 by Gerda Shank. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
127
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |