I really, really hate this "talking to myself" feeling I'm getting on
this mailing list.
I can confirm that there is some bug in handling deflate in
Element::DateTime.
Here is how:
====== minimal example
file: futest.yaml
method: post
auto_fieldset: 1
auto_label: '%n'
elements:
- type: DateTime
# - type: Text
name: valid_until
# auto_inflate: 1
deflators:
- type: Callback
callback: "A::deflate"
inflators:
- type: Callback
callback: "A::inflate"
file: futest.pl
#!/usr/bin/perl -w
use strict;
use HTML::FormFu;
use CGI;
my $cgi = CGI->new;
my $form = HTML::FormFu->new;
$form->load_config_file('futest.yaml');
$form->process( $cgi );
if ( $form->submitted_and_valid ) {
# do something with $form->params
} else {
# display the form
$form->default_values({valid_until => time});
print $form;
}
package A;
use DateTime;
sub deflate {
warn "Deflate with ".join(',',@_)."\n";
my $d = DateTime->from_epoch(epoch=>$_[0]);
return $d;
}
sub inflate {
warn "Inflate with ".join(',',@_)."\n";
}
1;
If I leave type: Text uncommented (while keeping the DateTime commented)
in the yaml file, everything
works, the deflate routine gets called, proper values display in the form.
Comment Text, uncomment DateTime, NO OTHER changes to anything else, I
get error saying format
is wrong.
So can somebody please look into this problem? Or has FormFu been
abandoned by it's authors?
On 06/07/2010 11:10 AM, Matija Grabnar wrote:
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@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
_______________________________________________
HTML-FormFu mailing list
HTML-FormFu@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
_______________________________________________
HTML-FormFu mailing list
HTML-FormFu@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu