[html-formfu] Date element and invalid default value

Ronald J Kimball rkimball+formfu at pangeamedia.com
Tue Jul 7 16:23:08 GMT 2009


I am using HTML::FormFu in an app that passes default values in via 
hidden form fields.  With the Date element, if the hidden field doesn't 
have a value, the default gets set to empty string and an error occurs 
when the element is created:

[error] Caught exception in MyApp::Controller::Root->form "Invalid date 
format:  at /usr/local/lib/perl5/site_perl/5.10.0/Catalyst/Action.pm 
line 59"


The error occurs here, in _date_defaults():

             my $builder = DateTime::Format::Builder->new;
             $builder->parser( { strptime => $self->strftime } );

             $default = $builder->parse_datetime($default);

My solution was simply to change the third line to:

             $default = eval { $builder->parse_datetime($default) };

So if the default is invalid, it's effectively ignored, which is what I 
want.


Is there a better way to handle this situation?

thanks,
Ronald



More information about the HTML-FormFu mailing list