line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Rose::HTML::Form::Field::OptionGroup; |
2
|
|
|
|
|
|
|
|
3
|
11
|
|
|
11
|
|
107488
|
use strict; |
|
11
|
|
|
|
|
37
|
|
|
11
|
|
|
|
|
352
|
|
4
|
|
|
|
|
|
|
|
5
|
11
|
|
|
11
|
|
1029
|
use Rose::HTML::Form::Field::Option::Container; |
|
11
|
|
|
|
|
40
|
|
|
11
|
|
|
|
|
146
|
|
6
|
|
|
|
|
|
|
# XXX: Use runtime inheritance here to avoid race in circular dependency |
7
|
|
|
|
|
|
|
our @ISA = qw(Rose::HTML::Form::Field::Option::Container); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Rose::Object::MakeMethods::Generic |
10
|
|
|
|
|
|
|
( |
11
|
11
|
|
|
|
|
72
|
scalar => 'name', |
12
|
|
|
|
|
|
|
boolean => 'multiple', |
13
|
11
|
|
|
11
|
|
404
|
); |
|
11
|
|
|
|
|
25
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.606'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
__PACKAGE__->add_required_html_attrs( |
18
|
|
|
|
|
|
|
{ |
19
|
|
|
|
|
|
|
label => '', |
20
|
|
|
|
|
|
|
}); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
__PACKAGE__->add_boolean_html_attrs('disabled'); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
__PACKAGE__->delete_valid_html_attrs(qw( |
25
|
|
|
|
|
|
|
name |
26
|
|
|
|
|
|
|
value |
27
|
|
|
|
|
|
|
onblur |
28
|
|
|
|
|
|
|
onfocus |
29
|
|
|
|
|
|
|
accesskey |
30
|
|
|
|
|
|
|
tabindex)); |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
0
|
1
|
0
|
sub element { 'optgroup' } |
33
|
66
|
|
|
66
|
1
|
350
|
sub html_element { 'optgroup' } |
34
|
32
|
|
|
32
|
1
|
196
|
sub xhtml_element { 'optgroup' } |
35
|
|
|
|
|
|
|
|
36
|
11
|
|
|
11
|
1
|
133
|
sub label { shift->html_attr('label', @_) } |
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
1
|
1
|
5
|
sub html { shift->html_field(@_) } |
39
|
1
|
|
|
1
|
1
|
7
|
sub xhtml { shift->xhtml_field(@_) } |
40
|
|
|
|
|
|
|
|
41
|
6
|
|
|
6
|
0
|
76
|
sub init_apply_error_class { 0 } |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub hidden |
44
|
|
|
|
|
|
|
{ |
45
|
34
|
|
|
34
|
0
|
66
|
my($self) = shift; |
46
|
|
|
|
|
|
|
|
47
|
34
|
100
|
|
|
|
82
|
if(@_) |
48
|
|
|
|
|
|
|
{ |
49
|
6
|
|
|
|
|
21
|
my $bool = shift; |
50
|
|
|
|
|
|
|
|
51
|
6
|
|
|
|
|
33
|
$self->SUPER::hidden($bool); |
52
|
|
|
|
|
|
|
|
53
|
6
|
|
|
|
|
17
|
foreach my $option ($self->options) |
54
|
|
|
|
|
|
|
{ |
55
|
12
|
|
|
|
|
32
|
$option->hidden($bool); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
34
|
|
|
|
|
124
|
return $self->SUPER::hidden(@_); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__END__ |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 NAME |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Rose::HTML::Form::Field::OptionGroup - Object representation of a group of options in a pop-up menu or select box in an HTML form. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 SYNOPSIS |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
$field = |
73
|
|
|
|
|
|
|
Rose::HTML::Form::Field::OptionGroup->new( |
74
|
|
|
|
|
|
|
name => 'fruits', |
75
|
|
|
|
|
|
|
label => 'Fruits'); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$field->options(apple => 'Apple', |
78
|
|
|
|
|
|
|
orange => 'Orange', |
79
|
|
|
|
|
|
|
grape => 'Grape'); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
print $field->html; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
... |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 DESCRIPTION |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
L<Rose::HTML::Form::Field::OptionGroup> is an object representation of a group of options in a pop-up menu or select box in an HTML form. Yes, this is the often-overlooked (and sometimes ill-supported) "optgroup" HTML tag. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This class inherits from, and follows the conventions of, L<Rose::HTML::Form::Field>. Inherited methods that are not overridden will not be documented a second time here. See the L<Rose::HTML::Form::Field> documentation for more information. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 HTML ATTRIBUTES |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Valid attributes: |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
accesskey |
96
|
|
|
|
|
|
|
class |
97
|
|
|
|
|
|
|
dir |
98
|
|
|
|
|
|
|
disabled |
99
|
|
|
|
|
|
|
id |
100
|
|
|
|
|
|
|
label |
101
|
|
|
|
|
|
|
lang |
102
|
|
|
|
|
|
|
name |
103
|
|
|
|
|
|
|
onblur |
104
|
|
|
|
|
|
|
onclick |
105
|
|
|
|
|
|
|
ondblclick |
106
|
|
|
|
|
|
|
onfocus |
107
|
|
|
|
|
|
|
onkeydown |
108
|
|
|
|
|
|
|
onkeypress |
109
|
|
|
|
|
|
|
onkeyup |
110
|
|
|
|
|
|
|
onmousedown |
111
|
|
|
|
|
|
|
onmousemove |
112
|
|
|
|
|
|
|
onmouseout |
113
|
|
|
|
|
|
|
onmouseover |
114
|
|
|
|
|
|
|
onmouseup |
115
|
|
|
|
|
|
|
style |
116
|
|
|
|
|
|
|
tabindex |
117
|
|
|
|
|
|
|
title |
118
|
|
|
|
|
|
|
value |
119
|
|
|
|
|
|
|
xml:lang |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Required attributes: |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
label |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Boolean attributes: |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
disabled |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=over 4 |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=item B<new PARAMS> |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Constructs a new L<Rose::HTML::Form::Field::OptionGroup> object based on PARAMS, where PARAMS are name/value pairs. Any object method is a valid parameter name. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=back |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 OBJECT METHODS |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=over 4 |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item B<add_option OPTION> |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Convenience alias for L<add_options()|/add_options>. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=item B<add_options OPTIONS> |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Adds options to the option group. OPTIONS may be a reference to a hash of value/label pairs, a reference to an array of values, or a list of L<Rose::HTML::Form::Field::Option> objects. Passing an odd number of items in the value/label argument list causes a fatal error. Options passed as a hash reference are sorted by the keys of the hash according to the default behavior of Perl's built-in L<sort()|perlfunc/sort> function. Options are added to the end of the existing list of options. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item B<choices [OPTIONS]> |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
This is an alias for the L<options|/options> method. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item B<has_value VALUE> |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Returns true if VALUE is selected in the option group, false otherwise. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=item B<label [VALUE]> |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Get or set the value of the "label" HTML attribute. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=item B<labels [LABELS]> |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Get or set the labels for all values. If LABELS is a reference to a hash or a list of value/label pairs, then LABELS replaces all existing labels. Passing an odd number of items in the list version of LABELS causes a fatal error. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Returns a hash of value/label pairs in list context, or a reference to a hash in scalar context. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=item B<option VALUE> |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Returns the first option (according to the order that they are returned from L<options()|/options>) whose "value" HTML attribute is VALUE, or undef if no such option exists. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=item B<options OPTIONS> |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Get or set the full list of options in the pop-up menu. OPTIONS may be a reference to a hash of value/label pairs, a reference to an array of values, or a list of L<Rose::HTML::Form::Field::Option> objects. Passing an odd number of items in the value/label argument list causes a fatal error. Options passed as a hash reference are sorted by the keys of the hash according to the default behavior of Perl's built-in L<sort()|perlfunc/sort> function. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
To set an ordered list of option values along with labels in the constructor, use both the L<options()|/options> and L<labels()|/labels> methods in the correct order. Example: |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
$field = |
180
|
|
|
|
|
|
|
Rose::HTML::Form::Field::OptionGroup->new( |
181
|
|
|
|
|
|
|
name => 'fruits', |
182
|
|
|
|
|
|
|
options => [ 'apple', 'pear' ], |
183
|
|
|
|
|
|
|
labels => { apple => 'Apple', pear => 'Pear' }); |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Remember that methods are called in the order that they appear in the constructor arguments (see the L<Rose::Object> documentation), so L<options()|/options> will be called before L<labels()|/labels> in the example above. This is important; it will not work in the opposite order. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Returns a list of the pop-up menu's L<Rose::HTML::Form::Field::Option> objects in list context, or a reference to an array of the same in scalar context. These are the actual objects used in the field. Modifying them will modify the field itself. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=item B<value_label> |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Returns the label of the first selected value (according to the order that they are returned by L<internal_value()|Rose::HTML::Form::Field/internal_value>), or the value itself if it has no label. If no value is selected, undef is returned. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=back |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head1 AUTHOR |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
John C. Siracusa (siracusa@gmail.com) |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head1 LICENSE |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Copyright (c) 2010 by John C. Siracusa. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |