line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormHandler::Widget::Field::Select; |
2
|
|
|
|
|
|
|
# ABSTRACT: select field rendering widget |
3
|
|
|
|
|
|
|
$HTML::FormHandler::Widget::Field::Select::VERSION = '0.40067'; |
4
|
|
|
|
|
|
|
|
5
|
31
|
|
|
31
|
|
21588
|
use Moose::Role; |
|
31
|
|
|
|
|
49
|
|
|
31
|
|
|
|
|
280
|
|
6
|
31
|
|
|
31
|
|
114074
|
use namespace::autoclean; |
|
31
|
|
|
|
|
53
|
|
|
31
|
|
|
|
|
299
|
|
7
|
31
|
|
|
31
|
|
1995
|
use HTML::FormHandler::Render::Util ('process_attrs'); |
|
31
|
|
|
|
|
47
|
|
|
31
|
|
|
|
|
275
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub render { |
10
|
36
|
|
|
36
|
0
|
67
|
my ( $self, $result ) = @_; |
11
|
36
|
|
66
|
|
|
443
|
$result ||= $self->result; |
12
|
36
|
50
|
|
|
|
86
|
die "No result for form field '" . $self->full_name . "'. Field may be inactive." unless $result; |
13
|
36
|
|
|
|
|
127
|
my $output = $self->render_element( $result ); |
14
|
36
|
|
|
|
|
149
|
return $self->wrap_field( $result, $output ); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub render_element { |
18
|
37
|
|
|
37
|
0
|
50
|
my ( $self, $result ) = @_; |
19
|
37
|
|
33
|
|
|
79
|
$result ||= $self->result; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# create select element |
22
|
37
|
|
|
|
|
124
|
my $output = $self->render_select_start( $result ); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# create empty select |
25
|
37
|
100
|
|
|
|
1156
|
if( defined $self->empty_select ) { |
26
|
3
|
|
|
|
|
14
|
$output .= $self->render_empty_select; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# loop through options |
30
|
37
|
|
|
|
|
93
|
foreach my $option ( @{ $self->{options} } ) { |
|
37
|
|
|
|
|
105
|
|
31
|
129
|
100
|
|
|
|
284
|
if ( my $label = $option->{group} ) { |
32
|
3
|
50
|
|
|
|
79
|
$label = $self->_localize( $label ) if $self->localize_labels; |
33
|
3
|
|
|
|
|
5
|
$output .= qq{\n<optgroup label="$label">}; |
34
|
3
|
|
|
|
|
4
|
foreach my $group_opt ( @{ $option->{options} } ) { |
|
3
|
|
|
|
|
4
|
|
35
|
9
|
|
|
|
|
16
|
$output .= $self->render_option( $group_opt, $result ); |
36
|
|
|
|
|
|
|
} |
37
|
3
|
|
|
|
|
5
|
$output .= qq{\n</optgroup>}; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
else { |
40
|
126
|
|
|
|
|
266
|
$output .= $self->render_option( $option, $result ); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
37
|
|
|
|
|
1306
|
$self->reset_options_index; |
44
|
|
|
|
|
|
|
|
45
|
37
|
|
|
|
|
69
|
$output .= '</select>'; |
46
|
37
|
|
|
|
|
74
|
return $output; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub render_select_start { |
50
|
37
|
|
|
37
|
0
|
56
|
my ( $self, $result ) = @_; |
51
|
37
|
|
33
|
|
|
75
|
$result ||= $self->result; |
52
|
|
|
|
|
|
|
|
53
|
37
|
|
|
|
|
981
|
my $id = $self->id; |
54
|
37
|
|
|
|
|
885
|
my $output = '<select name="' . $self->html_name . qq{" id="$id"}; |
55
|
37
|
100
|
|
|
|
990
|
$output .= ' multiple="multiple"' if $self->multiple; |
56
|
37
|
100
|
|
|
|
1013
|
$output .= ' size="' . $self->size . '"' if defined $self->size; |
57
|
37
|
|
|
|
|
186
|
$output .= process_attrs($self->element_attributes($result)); |
58
|
37
|
|
|
|
|
78
|
$output .= '>'; |
59
|
37
|
|
|
|
|
80
|
return $output; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub render_empty_select { |
63
|
3
|
|
|
3
|
0
|
6
|
my $self = shift; |
64
|
|
|
|
|
|
|
|
65
|
3
|
|
|
|
|
78
|
my $label = $self->_localize($self->empty_select); |
66
|
3
|
|
|
|
|
82
|
my $id = $self->id . "." . $self->options_index; |
67
|
3
|
|
|
|
|
11
|
my $output .= qq{\n<option value="" id="$id">$label</option>}; |
68
|
3
|
|
|
|
|
126
|
$self->inc_options_index; |
69
|
3
|
|
|
|
|
10
|
return $output; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub render_option { |
73
|
135
|
|
|
135
|
0
|
142
|
my ( $self, $option, $result ) = @_; |
74
|
135
|
|
33
|
|
|
238
|
$result ||= $self->result; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# current values |
77
|
135
|
|
|
|
|
332
|
my $fif = $result->fif; |
78
|
135
|
|
|
|
|
142
|
my %fif_lookup; |
79
|
135
|
100
|
|
|
|
3244
|
@fif_lookup{@$fif} = () if $self->multiple; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# not sure why the value of an option would be undef, but just in case, |
82
|
|
|
|
|
|
|
# set to empty string because of 'eq' below |
83
|
135
|
50
|
|
|
|
610
|
my $value = defined $option->{value} ? $option->{value} : ''; |
84
|
135
|
|
|
|
|
3010
|
my $id = $self->id . '.' . $self->options_index; |
85
|
135
|
|
|
|
|
4052
|
my $output .= qq{\n<option value="} . $self->html_filter($value) . '"'; |
86
|
135
|
|
|
|
|
206
|
$output .= qq{ id="$id"}; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# handle option attributes |
89
|
135
|
|
50
|
|
|
457
|
my $attrs = $option->{attributes} || {}; |
90
|
135
|
0
|
33
|
|
|
263
|
if( defined $option->{disabled} && $option->{disabled} ) { |
91
|
0
|
|
|
|
|
0
|
$attrs->{disabled} = 'disabled'; |
92
|
|
|
|
|
|
|
} |
93
|
135
|
100
|
100
|
|
|
3485
|
if ( defined $fif && |
|
|
|
33
|
|
|
|
|
94
|
|
|
|
|
|
|
( ( $self->multiple && exists $fif_lookup{$value} ) || |
95
|
|
|
|
|
|
|
( $fif eq $value ) ) ) { |
96
|
30
|
|
|
|
|
66
|
$attrs->{selected} = 'selected'; |
97
|
|
|
|
|
|
|
} |
98
|
135
|
|
|
|
|
336
|
$output .= process_attrs($attrs); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# handle label |
101
|
135
|
|
|
|
|
189
|
my $label = $option->{label}; |
102
|
135
|
50
|
|
|
|
3618
|
$label = $self->_localize($label) if $self->localize_labels; |
103
|
135
|
|
|
|
|
4167
|
$output .= '>' . ( $self->html_filter($label) ) . '</option>'; |
104
|
135
|
|
|
|
|
4300
|
$self->inc_options_index; |
105
|
135
|
|
|
|
|
463
|
return $output; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
__END__ |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=pod |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=encoding UTF-8 |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 NAME |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
HTML::FormHandler::Widget::Field::Select - select field rendering widget |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 VERSION |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
version 0.40067 |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 DESCRIPTION |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Renders single and multiple selects. Options hashrefs must |
127
|
|
|
|
|
|
|
have 'value' and 'label' keys, and may have an 'attributes' key. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
See L<HTML::FormHandler::Field::Select> for documentation on |
130
|
|
|
|
|
|
|
select fields and options. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 NAME |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
HTML::FormHandler::Widget::Field::Select |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 AUTHOR |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
FormHandler Contributors - see HTML::FormHandler |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
This software is copyright (c) 2016 by Gerda Shank. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
145
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=cut |