Skip to content

Commit

Permalink
Add message for no message... Add test for failed DateTime
Browse files Browse the repository at this point in the history
  • Loading branch information
gshank committed Apr 22, 2009
1 parent 6bdcc67 commit 3e64576
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
16 changes: 11 additions & 5 deletions lib/HTML/FormHandler/Field.pm
Original file line number Diff line number Diff line change
Expand Up @@ -747,9 +747,13 @@ See $form->language_handle for details. Returns undef.

sub add_error
{
my $self = shift;
my ($self, @message) = @_;

my $lh;
unless( defined $message[0] )
{
@message = ('field is invalid');
}
# Running without a form object?
if ( $self->form )
{
Expand All @@ -761,8 +765,9 @@ sub add_error
|| HTML::FormHandler::I18N->get_handle
|| die "Failed call to Locale::Maketext->get_handle";
}
$self->push_errors( $lh->maketext(@_) ) unless $self->errors_on_parent;
$self->parent->push_errors( $lh->maketext(@_) ) if $self->parent;
my $message = $lh->maketext(@message);
$self->push_errors( $message ) unless $self->errors_on_parent;
$self->parent->push_errors( $message ) if $self->parent;
return;
}

Expand Down Expand Up @@ -825,6 +830,7 @@ sub validate_field
sub _apply_actions
{
my $self = shift;

for my $action ( @{ $self->apply || [] } )
{
my $input = $self->value;
Expand Down Expand Up @@ -879,8 +885,8 @@ sub _apply_actions
}
elsif ( ref $action->{transform} eq 'CODE' )
{
my $new_value;
eval { $new_value = $action->{transform}->($input); };
$DB::single=1;
my $new_value = eval { $action->{transform}->($input) };
if ($@)
{
$error_message = $@;
Expand Down
3 changes: 2 additions & 1 deletion t/filters.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use DateTime;

BEGIN
{
plan tests => 10;
plan tests => 11;
}

{
Expand Down Expand Up @@ -98,6 +98,7 @@ $form->validate($params);

is( $form->field('sprintf_filter')->value, '<1e+02>', 'sprintf filter' );
ok( $form->field('date_time_error')->has_errors, 'DateTime error catched' );
ok( $form->field('date_time_error')->errors->[0] ne 'field is invalid', 'error message');
is( ref $form->field('date_time')->value, 'DateTime', 'DateTime object created' );
ok( $form->field('coerce_error')->has_errors, 'no suitable coercion - error' );
is( $form->field('coerce_pass')->value, 10, 'coercion filter' );
Expand Down

0 comments on commit 3e64576

Please sign in to comment.