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.40067'; |
4
|
1
|
|
|
1
|
|
874
|
use Moose::Role; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
13
|
|
5
|
1
|
|
|
1
|
|
3965
|
use namespace::autoclean; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
10
|
|
6
|
1
|
|
|
1
|
|
66
|
use HTML::FormHandler::Render::Util ('process_attrs'); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub render { |
10
|
1
|
|
|
1
|
0
|
3
|
my ( $self, $result ) = @_; |
11
|
1
|
|
33
|
|
|
34
|
$result ||= $self->result; |
12
|
1
|
50
|
|
|
|
7
|
die "No result for form field '" . $self->full_name . "'. Field may be inactive." unless $result; |
13
|
1
|
|
|
|
|
4
|
my $output = $self->render_element( $result ); |
14
|
1
|
|
|
|
|
5
|
return $self->wrap_field( $result, $output ); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub render_element { |
18
|
1
|
|
|
1
|
0
|
2
|
my ( $self, $result ) = @_; |
19
|
1
|
|
33
|
|
|
2
|
$result ||= $self->result; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# loop through options |
23
|
1
|
|
|
|
|
2
|
my $output = ''; |
24
|
1
|
|
|
|
|
1
|
foreach my $option ( @{ $self->{options} } ) { |
|
1
|
|
|
|
|
4
|
|
25
|
4
|
50
|
|
|
|
7
|
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
|
|
|
|
|
8
|
$output .= $self->render_option( $option, $result ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
1
|
|
|
|
|
39
|
$self->reset_options_index; |
42
|
1
|
|
|
|
|
2
|
return $output; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub render_option { |
46
|
4
|
|
|
4
|
0
|
6
|
my ( $self, $option, $result ) = @_; |
47
|
4
|
|
33
|
|
|
7
|
$result ||= $self->result; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# get existing values |
50
|
4
|
|
|
|
|
11
|
my $fif = $result->fif; |
51
|
4
|
|
|
|
|
2
|
my %fif_lookup; |
52
|
4
|
50
|
|
|
|
100
|
@fif_lookup{@$fif} = () if $self->multiple; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# create option label attributes |
55
|
4
|
|
50
|
|
|
15
|
my $lattr = $option->{label_attributes} || {}; |
56
|
4
|
|
|
|
|
12
|
my $lattr_str = process_attrs( $lattr ); |
57
|
|
|
|
|
|
|
|
58
|
4
|
|
|
|
|
94
|
my $id = $self->id . '.' . $self->options_index; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# start wrapping div |
61
|
4
|
|
|
|
|
5
|
my $output = qq{<div class="checkbox">}; |
62
|
|
|
|
|
|
|
|
63
|
4
|
|
|
|
|
9
|
$output .= qq{\n<label$lattr_str for="$id">}; |
64
|
4
|
|
|
|
|
5
|
my $value = $option->{value}; |
65
|
4
|
|
|
|
|
4
|
$output .= qq{\n<input type="checkbox"}; |
66
|
4
|
|
|
|
|
124
|
$output .= qq{ value="} . $self->html_filter($value) . '"'; |
67
|
4
|
|
|
|
|
90
|
$output .= qq{ name="} . $self->html_name . '"'; |
68
|
4
|
|
|
|
|
5
|
$output .= qq{ id="$id"}; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# handle option attributes |
71
|
4
|
|
50
|
|
|
24
|
my $attr = $option->{attributes} || {}; |
72
|
4
|
0
|
33
|
|
|
9
|
if( defined $option->{disabled} && $option->{disabled} ) { |
73
|
0
|
|
|
|
|
0
|
$attr->{disabled} = 'disabled'; |
74
|
|
|
|
|
|
|
} |
75
|
4
|
50
|
33
|
|
|
102
|
if ( defined $fif && |
|
|
|
33
|
|
|
|
|
76
|
|
|
|
|
|
|
( ( $self->multiple && exists $fif_lookup{$value} ) || |
77
|
|
|
|
|
|
|
( $fif eq $value ) ) ) { |
78
|
0
|
|
|
|
|
0
|
$attr->{checked} = 'checked'; |
79
|
|
|
|
|
|
|
} |
80
|
4
|
|
|
|
|
9
|
$output .= process_attrs($attr); |
81
|
4
|
|
|
|
|
5
|
$output .= " />\n"; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# handle label |
84
|
4
|
|
|
|
|
3
|
my $label = $option->{label}; |
85
|
4
|
50
|
|
|
|
109
|
$label = $self->_localize($label) if $self->localize_labels; |
86
|
4
|
|
|
|
|
113
|
$output .= $self->html_filter($label); |
87
|
4
|
|
|
|
|
6
|
$output .= "\n</label>"; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# close wrapping div |
90
|
4
|
|
|
|
|
4
|
$output .= "\n</div>"; |
91
|
|
|
|
|
|
|
|
92
|
4
|
|
|
|
|
129
|
$self->inc_options_index; |
93
|
4
|
|
|
|
|
13
|
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.40067 |
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) 2016 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 |