Adds options to the pop-up menu. OPTIONS may take the following forms.
A reference to a hash of value/label pairs:
$field->add_options
(
{
value1 => 'label1',
value2 => 'label2',
...
}
);
An ordered list of value/label pairs:
$field->add_options
(
value1 => 'label1',
value2 => 'label2',
...
);
(Option values and labels passed as a hash reference are
sorted by the keys of the hash according to the default behavior of
Perl's built-in sort() function.)
A reference to an array of containing only plain scalar
values:
$field->add_options([ 'value1', 'value2', ... ]);
A list or reference to an array of
Rose::HTML::Form::Field::Option or Rose::HTML::Form::Field::OptionGroup
objects:
$field->add_options
(
Rose::HTML::Form::Field::Option->new(...),
Rose::HTML::Form::Field::OptionGroup->new(...),
Rose::HTML::Form::Field::Option->new(...),
...
);
$field->add_options
(
[
Rose::HTML::Form::Field::Option->new(...),
Rose::HTML::Form::Field::OptionGroup->new(...),
Rose::HTML::Form::Field::Option->new(...),
...
]
);
A list or reference to an array containing a mix of
value/label pairs, value/hashref pairs, and
Rose::HTML::Form::Field::Option or Rose::HTML::Form::Field::OptionGroup
objects:
@args =
(
# value/label pair
value1 => 'label1',
# option group object
Rose::HTML::Form::Field::OptionGroup->new(...),
# value/hashref pair
value2 =>
{
label => 'Some Label',
id => 'my_id',
...
},
# option object
Rose::HTML::Form::Field::Option->new(...),
...
);
$field->add_options(@args); # list
$field->add_options(\@args); # reference to an array
Please note: the second form (passing a reference to an
array) requires that at least one item in the referenced array is not a
plain scalar, lest it be confused with "a reference to an array of
containing only plain scalar values."
All options are added to the end of the existing list of
options.
Option groups may also be added by nesting another level of
array references. For example, this:
$field = Rose::HTML::Form::Field::PopUpMenu->new(name => 'fruits');
$field->options(apple => 'Apple',
orange => 'Orange',
grape => 'Grape');
$group = Rose::HTML::Form::Field::OptionGroup->new(label => 'Others');
$group->options(juji => 'Juji',
peach => 'Peach');
$field->add_options($group);
is equivalent to this:
$field =
Rose::HTML::Form::Field::PopUpMenu->new(
name => 'fruits',
options =>
[
apple => 'Apple',
orange => 'Orange',
grape => 'Grape',
Others =>
[
juji => { label => 'Juji' },
peach => { label => 'Peach' },
],
]);
$field->add_options($group);
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, an ordered list of value/label
pairs, a reference to an array of values, or a list of objects that are
of, or inherit from, the classes Rose::HTML::Form::Field::Option or
Rose::HTML::Form::Field::OptionGroup. 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 value according to the default behavior of
Perl's built-in sort() function.
To set an ordered list of option values along with labels in
the constructor, use both the options() and labels()
methods in the correct order. Example:
$field =
Rose::HTML::Form::Field::PopUpMenu->new(
name => 'fruits',
options => [ 'apple', 'pear' ],
labels => { apple => 'Apple', pear => 'Pear' });
Remember that methods are called in the order that they appear
in the constructor arguments (see the Rose::Object documentation), so
options() will be called before labels() in the example
above. This is important; it will not work in the opposite order.
Returns a list of the pop-up menu's
Rose::HTML::Form::Field::Option and/or
Rose::HTML::Form::Field::OptionGroup objects in list context, or a
reference to an array of the same in scalar context. Hidden options
will be included in this list. These are the actual objects used
in the field. Modifying them will modify the field itself.