[html-formfu] Problem inflating to DateTime

Matija Grabnar matija at serverflow.com
Mon Jun 7 09:10:18 GMT 2010


More information:
I did a minimal test (using HTML::FormFu, without catalyst, with only a 
single DateTime field in the form),
and I still get the error. I can confirm that in this simplified 
scenario, the deflation function never gets called,
and the error is:

Invalid date format: 1275900620 at 
/usr/share/perl5/HTML/FormFu/Element/Date.pm line 164

Is this a bug in Element::DateTime, or do I fundamentaly misunderstand 
how inflation/deflation works?

On 06/05/2010 03:04 PM, Matija Grabnar wrote:
> 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
>      deflators:
>       - type: Callback
>         callback: "MyApp::Forms::epoch_to_datetime"
>      inflators:
>       - 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?
>
>
> _______________________________________________
> HTML-FormFu mailing list
> HTML-FormFu at lists.scsys.co.uk
> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu




More information about the HTML-FormFu mailing list