[html-formfu] HTML::FormFu::Model::DBIC only deleting or saving the
first has_many relationship in a Repeatable block
Byron Young
Byron.Young at riverbed.com
Thu Feb 28 09:18:29 GMT 2008
Hi all,
I'm trying to create a form for my DBIC class that has the following
has_many relationship:
__PACKAGE__->has_many(
"module_parameters",
"NBT::IceBox::Schema::ModuleParameters",
{ "foreign.module" => "self.id" },
);
The HTML::FormFu::Model::DBIC doc says to create a Repeatable block,
which I've done. It works great for displaying the relationships -
everything is fille d out correctly and I see the right number of items.
I'm running into trouble, however, when I try to use the new_empty_row
and delete_if_true settings. It seems they only work for the first item
in the has_many list.
So, for example, if I have 4 module_parameters on my form and I check
'delete' for all of them and then submit, only the first one is deleted.
To be more specific, if I select 'delete' for the last 3
module_parameters, nothing is deleted.
Or, for new_empty_row, if I have no current module_parameters and I
enter something into the empty row's 'name' box, i will get a new
module_parameter as expected. But, if there are 1 or more
module_parameters already there, anything entered into the empty row is
ignored, and I can't get any new relationships added beyond the first.
Is this a bug or am I doing it wrong? I couldn't find anything on CPAN,
the google code site, the mailing list, or in the code itself that
explains it.
Here is my Repeatable block:
- type: Repeatable
nested_name: module_parameters
attributes:
class: block
db:
new_empty_row: name
elements:
- type: Hidden
name: id
- type: Text
name: name
label: Name
attributes:
title: Parameter name
- type: Checkbox
name: is_required
label: Required
value: 1
attributes:
title: Is this parameter required?
- type: Checkbox
name: is_enum
label: Enum
value: 1
attributes:
title: Is this an enumerated type?
- type: Checkbox
name: delete
label: Delete this parameter?
value: 1
attributes:
title: Check to delete this parameter
db:
delete_if_true: 1
And, for completion, my save method (pretty much the standard FormConfig
method. fetch() just grabs the object from the database or creates a
new one and puts it in the stash):
sub save : PathPart Chained('fetch') Args(0) FormConfig
{
my ($self, $c) = @_;
$c->stash->{title} = "Save " . $self->display_name;
my $f = $c->stash->{form};
my $o = $c->stash->{object};
# return if there was a problem with any param values
if (!$f->submitted_and_valid()) {
$c->log->debug("***CRUD.pm - found errors in form");
$c->log->debug($f->form_error_message);
$c->stash->{template} ||= $self->template;
return 0;
}
# re-set object's values from the now-valid form
$f->save_to_model($o);
$c->flash->{status_msg} = "Save successful";
$c->response->redirect($c->uri_for('', $o->id, 'view'));
}
Thanks,
Byron
More information about the HTML-FormFu
mailing list