Permalink
Browse files

add 'missing' method to field

  • Loading branch information...
1 parent e5bf8c6 commit 5dfa46597646b97de435b5271aae30f05abf9771 @gshank committed Apr 25, 2012
Showing with 30 additions and 0 deletions.
  1. +5 −0 lib/HTML/FormHandler/Field.pm
  2. +25 −0 t/field_setup/missing.t
@@ -583,6 +583,11 @@ has 'result' => (
);
has '_pin_result' => ( is => 'ro', reader => '_get_pin_result', writer => '_set_pin_result' );
+sub missing {
+ my $self = shift;
+ return $self->required && $self->validated && ( !$self->has_input || !$self->input_defined );
+}
+
sub has_input {
my $self = shift;
return unless $self->has_result;
View
@@ -0,0 +1,25 @@
+use strict;
+use warnings;
+use Test::More;
+
+{
+
+ package MyApp::Form::Test;
+ use HTML::FormHandler::Moose;
+ extends 'HTML::FormHandler';
+
+ has '+name' => ( default => 'test_form' );
+
+ has_field 'foo' => ( required => 1 );
+ has_field 'bar' => ( required => 1 );;
+}
+
+my $form = MyApp::Form::Test->new;
+$form->process( params => {} );
+ok( ! $form->field('bar')->missing, 'bar is not missing' );
+ok( ! $form->field('foo')->missing, 'foo is not missing' );
+$form->process( params => { foo => 'my_foo', bar => '' } );
+ok( $form->field('bar')->missing, 'bar is missing' );
+ok( ! $form->field('foo')->missing, 'foo is not missing' );
+
+done_testing;

0 comments on commit 5dfa465

Please sign in to comment.