package Rose::HTML::Form::Field::RadioButtonGroup; use strict; use Carp; use Rose::HTML::Form::Field::RadioButton; use Rose::HTML::Form::Field::Group; use base 'Rose::HTML::Form::Field::Group::OnOff'; our $VERSION = '0.606'; sub _item_class { shift->object_type_class_loaded('radio button') } sub _item_name { 'radio button' } sub _item_name_plural { 'radio buttons' } *radio_buttons = \&Rose::HTML::Form::Field::Group::items; *radio_buttons_localized = \&Rose::HTML::Form::Field::Group::items_localized; *radio_button = \&Rose::HTML::Form::Field::Group::OnOff::item; *visible_radio_buttons = \&Rose::HTML::Form::Field::Group::visible_items; *add_radio_buttons = \&Rose::HTML::Form::Field::Group::add_items; *add_radio_button = \&add_radio_buttons; *add_radio_buttons_localized = \&Rose::HTML::Form::Field::Group::add_items_localized; *add_radio_button_localized = \&add_radio_buttons_localized; *choices = \&radio_buttons; *choices_localized = \&radio_buttons_localized; *show_all_radio_buttons = \&Rose::HTML::Form::Field::Group::show_all_items; *hide_all_radio_buttons = \&Rose::HTML::Form::Field::Group::hide_all_items; *delete_radio_button = \&Rose::HTML::Form::Field::Group::delete_item; *delete_radio_buttons = \&Rose::HTML::Form::Field::Group::delete_items; *delete_radio_button_group = \&Rose::HTML::Form::Field::Group::delete_item_group; *delete_radio_button_groups = \&Rose::HTML::Form::Field::Group::delete_item_groups; *radio_buttons_html_attr = \&Rose::HTML::Form::Field::Group::items_html_attr; *delete_radio_buttons_html_attr = \&Rose::HTML::Form::Field::Group::delete_items_html_attr; sub internal_value { my($self) = shift; my($value) = $self->SUPER::internal_value(@_); return $value; } sub html_table { my($self, %args) = @_; $args{'class'} = defined $args{'class'} ? "$args{'class'} radio-button-group" : 'radio-button-group'; #$args{'cellpadding'} = 2 unless(exists $args{'cellpadding'}); #$args{'cellspacing'} = 0 unless(exists $args{'cellspacing'}); #$args{'tr'} = { valign => 'top' } unless(exists $args{'tr'}); $args{'tr'} ||= {}; $args{'td'} ||= {}; $args{'table'}{'class'} = defined $args{'table'}{'class'} ? "$args{'table'}{'class'} radio-button-group" : defined $args{'class'} ? $args{'class'} : undef; #$args{'table'}{'cellpadding'} = $args{'cellpadding'} # unless((exists $args{'table'} && !defined $args{'table'}) || # exists $args{'table'}{'cellpadding'}); #$args{'table'}{'cellspacing'} = $args{'cellspacing'} # unless((exists $args{'table'} && !defined $args{'table'}) || # exists $args{'table'}{'cellspacing'}); if($args{'_xhtml'}) { return $self->SUPER::html_table(items => scalar $self->visible_radio_buttons, format_item => \&Rose::HTML::Form::Field::Group::_xhtml_item, %args); } else { return $self->SUPER::html_table(items => scalar $self->radio_buttons, format_item => \&Rose::HTML::Form::Field::Group::_html_item, %args); } } sub xhtml_table { shift->html_table(@_, _xhtml => 1) } 1; __END__ =head1 NAME Rose::HTML::Form::Field::RadioButtonGroup - A group of radio buttons in an HTML form. =head1 SYNOPSIS $field = Rose::HTML::Form::Field::RadioButtonGroup->new(name => 'fruits'); $field->radio_buttons(apple => 'Apple', orange => 'Orange', grape => 'Grape'); print $field->value_label('apple'); # 'Apple' $field->input_value('orange'); print $field->internal_value; # 'orange' print $field->html_table(columns => 2); ... =head1 DESCRIPTION L is an object wrapper for a group of radio buttons 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 A radio button group is an abstraction with no corresponding parent HTML element; the individual L objects in the group exist as siblings. As such, the list of L objects will always be empty and cannot be modified. To get the list of siblings, use the L method. 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 None. This class is simply an aggregator of L objects. =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 radio buttons to the radio button group. RADIO_BUTTONS may take the following forms. A reference to a hash of value/label pairs: $field->add_radio_buttons ( { value1 => 'label1', value2 => 'label2', ... } ); An ordered list of value/label pairs: $field->add_radio_buttons ( value1 => 'label1', value2 => 'label2', ... ); (Radio button values and labels passed as a hash reference are sorted by value 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_radio_buttons([ 'value1', 'value2', ... ]); A list or reference to an array of L objects: $field->add_radio_buttons ( Rose::HTML::Form::Field::RadioButton->new(...), Rose::HTML::Form::Field::RadioButton->new(...), ... ); $field->add_radio_buttons ( [ Rose::HTML::Form::Field::RadioButton->new(...), Rose::HTML::Form::Field::RadioButton->new(...), ... ] ); A list or reference to an array containing a mix of value/label pairs, value/hashref pairs, and L objects: @args = ( # value/label pair value1 => 'label1', # value/hashref pair value2 => { label => 'Some Label', id => 'my_id', ... }, # object Rose::HTML::Form::Field::RadioButton->new(...), ... ); $field->add_radio_buttons(@args); # list $field->add_radio_buttons(\@args); # reference to an array All radio buttons are added to the end of the existing list of radio buttons. 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." =item B This is an alias for the L method. =item B Get or set the default number of columns to use in the output of the L and L methods. =item B This is an alias for the L method. =item B Deletes the first radio button (according to the order that they are returned from L) whose "value" HTML attribute is VALUE. Returns the deleted radio button or undef if no such radio button exists. =item B Repeatedly calls L, passing each value in LIST. =item B Delete the HTML attribute named NAME from each L. =item B Returns true if the radio button whose value is VALUE is selected, false otherwise. =item B Set L