Skip to content

Commit

Permalink
handle SelectCSV field in as_label method of Select field
Browse files Browse the repository at this point in the history
  • Loading branch information
gshank committed Nov 26, 2013
1 parent 56fc32e commit baaf6c1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/HTML/FormHandler/Field/Select.pm
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,17 @@ sub as_label {
$value = $self->value unless defined $value;
return unless defined $value;
if ( $self->multiple ) {
unless ( ref($value) eq 'ARRAY' ) {
if( $self->has_inflate_default_method ) {
my @values = $self->inflate_default($value);
$value = \@values;
}
else {
# not sure under what circumstances this would happen, but
# just in case
return $value;
}
}
my @labels;
my %value_hash;
@value_hash{@$value} = ();
Expand Down
4 changes: 4 additions & 0 deletions t/fields/selectcsv.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use strict;
use warnings;
use Test::More;
use Test::Exception;

# tests the SelectCSV field
{
Expand Down Expand Up @@ -42,11 +43,14 @@ my $fif = $form->fif;
is_deeply( $fif, { foo => [1], bar => [1,2], box => [2] },
'fif is correct' );

lives_ok( sub { $form->field('bar')->as_label }, 'as_label works with SelectCSV field' );

my $rendered = $form->render;
ok( $rendered, 'rendering worked' );

my $params = { bar => [2,1] };
$form->process( $params );
lives_ok( sub { $form->field('bar')->as_label }, 'as_label works with SelectCSV field' );
$fif = $form->fif;
is_deeply( $fif, $params, 'fif ok' );
my $value = $form->value;
Expand Down

0 comments on commit baaf6c1

Please sign in to comment.