[html-formfu] How to split one object field into 2 form field ?

Carl Franks fireartist at gmail.com
Thu Jan 8 08:23:23 GMT 2009


2009/1/7  <hallouina-formfu at yahoo.fr>:
> Hello,
>
> happy new year everybody.
>
> I have an object "Account". I save into it a DATETIME field into my database. But in my form I have 2 fields : one for the date and an other for the time.
> So I create a DateTime object ( http://search.cpan.org/~drolsky/DateTime-0.4501/lib/DateTime.pm ) from this 2 fields and save it into the database.
>
>
> But to edit this object when I used   $form->model->default_values($contactmsg);
> the entire result (Date and Time) is loaded into my datemsg object. So I need to split this field into 2 field and load it by default into the edit form.
>
> Actually I do like that :
>
>
>
> sub editmsg : Local FormConfig('person/addmsg.yml') {
>    my ( $self, $c, $id_msg, $id_person ) = @_;
>
>    $c->stash->{template} = 'person/addmsg.tt2';
>
>    $id_person =~ /\d+/ or die 'invalid id';
>    my $contactmsg = $c->stash->{contactmsg} =
>      $c->model('DB::Contactmsg')->find($id_msg)
>      or die "Contactmsg $id_msg not found";
>
>    my $form = $c->stash->{form};
>
>    if ( $form->submitted_and_valid ) {
>
>        $form->save_to_model($contactmsg);
>        $c->response->redirect( $c->uri_for("/person/view/$id_person#tab1") );
>        $c->detach;
>    }
>    elsif ( !$form->submitted ) {
>        $form->model->default_values($contactmsg);
>    }
>
> }
>
>
>
> Please, how can I do to load by default my value and split it into my field "datemsg" and "timemsg" ?
>
> $form->model->default_values($contactmsg); load my entire object, but how can I do to overide one form field please ?

Hi Antoine,

HTML::FormFu::Deflator::CompoundDateTime should do what you want.

Cheers,
Carl



More information about the HTML-FormFu mailing list