use strict;
use warnings;
use Test::More tests => 11;
use HTML::FormFu;
use DateTime;
my $dt = DateTime->new( day => 6, month => 8, year => 2007 );
my $form = HTML::FormFu->new({ tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } });
$form->element('Date')->name('foo')->strftime("%m/%d/%Y")
->day( { prefix => '-- Day --', } )->month( {
prefix => '-- Month --',
short_names => 1,
}
)->year( {
prefix => '-- Year --',
list => [ 2007 .. 2017 ],
} )->default($dt)->auto_inflate(1)->constraint('Required');
$form->element('Date')->name('bar')->default('14-08-2007')
->year( { list => [ 2007 .. 2017 ] } );
$form->process;
is( "$form", <
HTML
$form->process( {
'foo_day', 30, 'foo_month', 6, 'foo_year', 2007,
'bar_day', 1, 'bar_month', 7, 'bar_year', 2007,
} );
ok( $form->submitted_and_valid );
my $foo = $form->param('foo');
my $bar = $form->param('bar');
isa_ok( $foo, 'DateTime' );
ok( !ref $bar );
is( $foo, "06/30/2007" );
is( $bar, "01-07-2007" );
is( "$form", <
HTML
# incorrect date
$form->process( { 'foo_day', 29, 'foo_month', 2, 'foo_year', 2007, } );
ok( $form->submitted );
ok( $form->has_errors );
ok( !defined $form->params->{foo} );
is( "$form", <
Invalid date
HTML_ERRORS