[html-formfu] Problem inflating to DateTime

Matija Grabnar matija at serverflow.com
Sat Jun 5 13:04:43 GMT 2010

I have a form which I get from a database row. One of the columns in the 
database is date/time in epoch format, and I want to transform it so 
that FormFu will display the DateTime element.

I was able to inflate the values I got from the  browser, because I 
could see what FormFu was passing to
my deflation routine, but I'm not able to get the deflation routine 
ready. I get the epoch string, and I tried returning either a DateTime 
object, or a date-and-time string.

I can see that the deflation gets called correctly. I can see that the 
DateTime object is correctly created
and returned to FormFu without error, but from Catalyst I get back

Caught exception in MyApp::Controller::Admin->coupon_edit "Invalid date 
format: 1318658400 at /usr/share/perl5/Catalyst/Action.pm line 65"

Note that this error message is very opaque: it reports the error from a 
location in Catalyst itself, with no indication where the error actually 
happened. Also note that it complains about my ORIGINAL value, NOT the 
just-deflated value that my deflation routine returned.

Here is the part of my form.yaml
    - type: DateTime
      name: valid_until
      auto_inflate: 1
       - type: Callback
         callback: "MyApp::Forms::epoch_to_datetime"
       - type: Callback
         callback: "MyApp::Forms::datetime_to_epoch"

I tried both WITH and WITHOUT auto_inflate.

This is my deflator routine:

sub epoch_to_datetime {
   foreach (@_) {
     warn "Parameter to deflate to datetime: [$_]\n";
   my $value = shift;
   return undef unless defined($value);
   $value = DateTime->from_epoch(epoch=>$value);
   warn "New value is $value\n";
   return $value;

Any ideas on what I could try? Is the deflated value thrown away in 
FormFu DateTime? Or is just the error message referencing the 
pre-deflated value to be more programmer friendly?

If so, what can I return so that the FormFu DateTime element will accept 
and display it?

More information about the HTML-FormFu mailing list