On 18/02/07, RA Jones <[EMAIL PROTECTED]> wrote:
[EMAIL PROTECTED] wrote:
> Hi Everyone,
>
> I have been experimenting with Catalyst::Controller::FormBuilder. I'm
> trying to provide an edit form for objects read from and written to the
> DB via DBIx::Class. Have FormBuilder automatically load the data from
> DBIC into the form seems pretty easy with something like:
>
> my $widget = $c->model('MyAppDB::Widget')->find($id);
> my $form = $self->formbuilder;
> $form->values($widget->get_columns);
>
>
> However, an elegant way of writing the data back out is not jumping out
> at me. I know I could manually copy each field out of the $form object
> to my $widget object, but it seems like there should be simple way to do
> it all in one line like I got with the
> "$form->values($widget->get_columns);" above.
>
> Any suggestions? What are other folks doing for C::C::FormBuilder and DBIC?
I'm pretty new to this, but this is what I did:
sub edit : Local Form {
# get data into form pretty much as above, then:
if ( $form->submitted && $form->validate ) {
$c->stash->{user} = $user;
$c->forward('do_edit');
}
sub do_edit : Private {
my ($self, $c) = @_;
my $form = $self->formbuilder;
my $fields = $form->field;
$c->stash->{user}->update($fields);
$c->flash->{status_msg} = 'User updated';
$c->response->redirect( $c->req->base . 'users/view/' .
$c->stash->{user}->id );
}
Not sure if it's the 'best' way, but it works. Will be interesting to
see what other suggestions you get.
It might be worth looking at the code for DBIx::Class::HTMLWidget for some ideas
http://search.cpan.org/src/ANDREMAR/DBIx-Class-HTMLWidget-0.09/lib/DBIx/Class/HTMLWidget.pm
When you're populating the form from the database, would your
$form->values($widget->get_columns);
correctly set select menus?
Also, (for all browsers that I'm aware of) no value is sent back to
the server for unchecked radioboxes - so it'd be worth checking
whether the "$fb->field" solution handles this properly.
(I don't know, as I've only read the formbuilder docs, I've never used it).
Cheers,
Carl
_______________________________________________
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/