package Rose::HTML::Form::Field::SelectBox; use strict; use Carp(); use Rose::HTML::Form::Field::Option::Container; our @ISA = qw(Rose::HTML::Form::Field::Option::Container); __PACKAGE__->add_required_html_attrs( { name => '', size => 5, }); __PACKAGE__->add_boolean_html_attrs ( 'multiple', ); __PACKAGE__->add_valid_html_attrs ( 'onchange', # %Script; #IMPLIED -- the element value was changed -- ); our $VERSION = '0.50'; sub multiple { shift->html_attr('multiple', @_) } 1; __END__ =head1 NAME Rose::HTML::Form::Field::SelectBox - Object representation of a select box in an HTML form. =head1 SYNOPSIS $field = Rose::HTML::Form::Field::SelectBox->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' $field->multiple(1); $field->add_value('grape'); print join(',', $field->internal_value); # 'grape,orange' $field->has_value('grape'); # true $field->has_value('apple'); # false print $field->html; ... =head1 DESCRIPTION L is an object representation of a select box 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 HTML ATTRIBUTES Valid attributes: accesskey class dir id lang multiple 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: multiple =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 select box. 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 L or L. 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 L function. Options are added to the end of the existing list of options. =item B Add VALUE to the list of selected values. =item B Add multiple values to the list of selected values. =item B This is an alias for the L method. =item B Returns true if VALUE is selected in the select box, false otherwise. =item B 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. Returns a hash of value/label pairs in list context, or a reference to a hash in scalar context. =item B This is just an accessor method for the "multiple" boolean HTML attribute, but I'm documenting it here so that I can warn that trying to select multiple values in a non-multiple-valued select box will cause a fatal error. =item B