-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged r2795 through r94889 from trunk to production.
Punch list changes, including relativization of xml paths. git-svn-id: svn://vm36.atech.tufts.edu/TAPER/production@94890 30e6160e-469f-4000-86ef-8ea788e09201
- Loading branch information
dorlea01
committed
Jan 26, 2011
1 parent
3c07965
commit 32fbb20
Showing
56 changed files
with
938 additions
and
501 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package HTML::FormFu::Element::RepeatableSelect; | ||
|
||
use strict; | ||
use base 'HTML::FormFu::Element::Select'; | ||
use MRO::Compat; | ||
use mro 'c3'; | ||
use Scalar::Util qw( reftype ); | ||
|
||
sub prepare_attrs { | ||
my ( $self, $render ) = @_; | ||
|
||
my $submitted = $self->form->submitted; | ||
my $default = $self->default; | ||
|
||
my $value | ||
= defined $self->name | ||
? $self->get_nested_hash_value( $self->form->input, $self->nested_name ) | ||
: undef; | ||
|
||
my $i = $self->_index_in_group; | ||
if ( defined $i ) { | ||
if ( ( reftype($value) || '' ) eq 'ARRAY' ) { | ||
$value = $value->[ $i ]; | ||
} | ||
if ( ( reftype($default) || '' ) eq 'ARRAY' ) { | ||
$default = $default->[ $i ]; | ||
} | ||
} | ||
|
||
if ( !$submitted && defined $default ) { | ||
for my $deflator ( @{ $self->_deflators } ) { | ||
$default = $deflator->process($default); | ||
} | ||
} | ||
|
||
for my $option ( @{ $render->{options} } ) { | ||
if ( exists $option->{group} ) { | ||
for my $item ( @{ $option->{group} } ) { | ||
$self->_prepare_attrs( $submitted, $value, $default, $item ); | ||
} | ||
} | ||
else { | ||
$self->_prepare_attrs( $submitted, $value, $default, $option ); | ||
} | ||
} | ||
|
||
# Skip the parent method. | ||
$self->HTML::FormFu::Element::_Input::prepare_attrs($render); | ||
|
||
return; | ||
} | ||
|
||
sub _index_in_group { | ||
my ( $self ) = @_; | ||
|
||
my $elems = $self->form->get_fields({ nested_name => $self->nested_name }); | ||
if ( $#$elems ) { | ||
# There are multiple fields with the same name; assume | ||
# none are multi-value fields, i.e. only one selected | ||
# option per field. (Otherwise it might be ambiguous | ||
# which option came from which field.) | ||
for ( 0 .. @$elems - 1 ) { | ||
if ( $self == $elems->[$_] ) { | ||
return $_; | ||
} | ||
} | ||
} | ||
} | ||
|
||
sub type { return 'Select'; } | ||
|
||
1; | ||
|
||
__END__ | ||
=head1 NAME | ||
HTML::FormFu::Element::RepeatableSelect - Select form field that can be inside a Repeatable | ||
=head1 METHODS | ||
=over | ||
=item prepare_attrs | ||
Override prepare_attrs of Select (actually defined in _Group) to fix | ||
the behavior when there are multiple fields with the same name. In | ||
this case, the value and default are arrays of values that correspond | ||
to the fields, so we have to pick out the one that corresponds to this | ||
field. | ||
=item type | ||
Returns 'Select' rather than 'RepeatableSelect' so that the HTML | ||
class comes out the same as a non-patched select. | ||
=back | ||
=head1 SEE ALSO | ||
Is a sub-class of, and inherits methods from | ||
L<HTML::FormFu::Element::Select>, | ||
L<HTML::FormFu::Element::_Group>, | ||
L<HTML::FormFu::Element::_Input>, | ||
L<HTML::FormFu::Element::_Field>, | ||
L<HTML::FormFu::Element> | ||
L<HTML::FormFu> | ||
=head1 AUTHOR | ||
Doug Orleans, C<dougorleans@gmail.com> | ||
=head1 LICENSE | ||
This library is free software, you can redistribute it and/or modify it under | ||
the same terms as Perl itself. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.