Skip to content

Commit

Permalink
check length in Repeatable before value method modifier, not ref
Browse files Browse the repository at this point in the history
  • Loading branch information
gshank committed May 31, 2011
1 parent 9187261 commit 657f45c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 47 deletions.
5 changes: 2 additions & 3 deletions lib/HTML/FormHandler/Field/Repeatable.pm
Expand Up @@ -293,6 +293,7 @@ sub _result_from_fields {

before 'value' => sub {
my $self = shift;

my @pk_elems =
map { $_->accessor } grep { $_->has_flag('is_primary_key') } $self->contains->all_fields
if $self->contains->has_flag('is_compound');
Expand All @@ -309,9 +310,7 @@ before 'value' => sub {
( !defined $element->{$pk} || $element->{$pk} eq '' );
}
next unless keys %$element;
next unless grep {
defined $_ && !ref $_ && $_ ne ''
} values %$element;
next unless grep { defined $_ && length $_ } values %$element;
}
push @new_value, $element;
}
Expand Down
1 change: 1 addition & 0 deletions lib/HTML/FormHandler/Field/Result.pm
Expand Up @@ -45,6 +45,7 @@ sub peek {
my $name = $self->field_def ? $self->field_def->full_name : $self->name;
my $type = $self->field_def ? $self->field_def->type : 'unknown';
my $string = $indent . "result " . $name . " type: " . $type . "\n";
$string .= $indent . "....value => " . $self->value . "\n" if $self->has_value;
if( $self->has_results ) {
$indent .= ' ';
foreach my $res ( $self->results ) {
Expand Down
31 changes: 31 additions & 0 deletions t/has_many.t
Expand Up @@ -192,4 +192,35 @@ is_deeply( $form->value, { employers => [], user_name => 'No Employer', occupati
'creates right value for empty repeatable' );
is_deeply( $form->fif, $unemployed_params, 'right fif for empty repeatable' );


# following tests Duration in a Repeatable, with no other subfield
{
package Form::RepeatableCompound;

use HTML::FormHandler::Moose;
extends 'HTML::FormHandler';

has_field timeslots => (type => 'Repeatable');

has_field 'timeslots.duration' => (type => 'Duration');
has_field 'timeslots.duration.hours' => (type => 'Integer');
has_field 'timeslots.duration.minutes' => (type => 'Integer');
}

$form = Form::RepeatableCompound->new;
my $params = {
'timeslots.0.id' => 'zero',
'timeslots.0.duration.hours' => 10,
'timeslots.0.duration.minutes' => 12,
'timeslots.1.id' => 'one',
'timeslots.1.duration.hours' => 2,
'timeslots.1.duration.minutes' => 1,
};

$form->process( params => $params );
ok( $form->validated, 'form validated' );
my $value = $form->value;
my $dur0 = DateTime::Duration->new( hours => 10, minutes => 12 );
is( $value->{timeslots}->[0]->{duration}->in_units('minutes'), $dur0->in_units('minutes'), 'got same duration' );

done_testing;
44 changes: 0 additions & 44 deletions t/repeatable_compound.t

This file was deleted.

0 comments on commit 657f45c

Please sign in to comment.