package Rose::HTML::Form::Field::PopUpMenu;
use strict;
use base 'Rose::HTML::Form::Field::SelectBox';
our $VERSION = '0.606';
__PACKAGE__->required_html_attr_value(size => 1);
__PACKAGE__->delete_valid_html_attr('multiple');
sub multiple { 0 }
sub internal_value
{
my($self) = shift;
my($value) = $self->SUPER::internal_value(@_);
return $value;
}
1;
__END__
=head1 NAME
Rose::HTML::Form::Field::PopUpMenu - Object representation of a pop-up menu in an HTML form.
=head1 SYNOPSIS
$field = Rose::HTML::Form::Field::PopUpMenu->new(name => 'fruits');
$field->options(apple => 'Apple',
orange => 'Orange',
grape => 'Grape');
print $field->value_label('apple'); # 'Apple'
$field->input_value('orange');
print $field->internal_value; # 'orange'
print $field->html;
...
=head1 DESCRIPTION
L is an object representation of a pop-up menu field in an HTML form.
This class inherits from, and follows the conventions of, L. Inherited methods that are not overridden will not be documented a second time here. See the L documentation for more information.
=head1 HIERARCHY
All L methods are effectively aliases for the option manipulation methods described below. See the "hierarchy" sections of the L and L documentation for an overview of the relationship between field and form objects and the child-related methods inherited from L.
=head1 HTML ATTRIBUTES
Valid attributes:
accesskey
class
dir
disabled
id
lang
name
onblur
onchange
onclick
ondblclick
onfocus
onkeydown
onkeypress
onkeyup
onmousedown
onmousemove
onmouseout
onmouseover
onmouseup
size
style
tabindex
title
value
xml:lang
Required attributes:
name
size
Boolean attributes:
disabled
=head1 CONSTRUCTOR
=over 4
=item B
Constructs a new L object based on PARAMS, where PARAMS are name/value pairs. Any object method is a valid parameter name.
=back
=head1 OBJECT METHODS
=over 4
=item B
Convenience alias for L.
=item B
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 L function.)
A reference to an array of containing B plain scalar values:
$field->add_options([ 'value1', 'value2', ... ]);
A list or reference to an array of L or L 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 L or L 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
B 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);
=item B
This is an alias for the L method.
=item B
This is an alias for the L method.
=item B
Deletes the first option (according to the order that they are returned from L) whose "value" HTML attribute is VALUE. Returns the deleted option or undef if no such option exists.
=item B
Repeatedly calls L, passing each value in LIST as an arugment.
=item B
Deletes the first option group (according to the order that they are returned from L) whose "label" HTML attribute is LABEL. Returns the deleted option group or undef if no such option exists.
=item B
Repeatedly calls L, passing each value in LIST.
=item B
Delete the L named NAME from each L