I had this same problem back in this thread
http://lists.scsys.co.uk/pipermail/html-formfu/2009-March/001884.html
the answer was how I was calling the new record. I eeded to use
find_or_new to call a new record.
my $book = $c->model('DB::MyTable')->find_or_new({ id => $id });
Mario Minati wrote:
Hi Greg,
I don't see the hidden line_cnt field, but I guess you just didn't post it as
editing works.
Maybe you have anycustom DBIC stuff hosing your setup?
If not it would be usefull to create a test out of your code that currently
fails.
Greets,
Mario Minati
Am Donnerstag 07 Mai 2009 23:13:10 schrieb Greg Coates:
OK. Let me try again, then.
I have a form that is used to display invoices from a table called
'invoices'. It contains a Repeatable that is used to display the
individual lines for those invoices. These lines come from a table
called 'invoice_items'.
When the form is used on an existing record, all is well. However, when
I use the form to create a new record, I have a problem. Instead of the
Repeatable being blank, every row from the 'invoice_items' table is
displayed.
Greg
Mario Minati wrote:
Your problem description seems to be missing a few words, actually I
don't understand your problem.
Greets,
Mario Minati
Am Mittwoch 06 Mai 2009 01:05:18 schrieb Greg Coates:
I have a form that contains a repeatable block that I'm using with
Catalyst. Everything works fine for existing master records. However,
when I use the form to create a new record, every record in the table
for the has many relationship. This is less than optimal.
Here's the repeatable block from the form definition:
- type: Repeatable
name: invoice_lines
nested_name: invoice_items
counter_name: line_cnt
auto_id: "%n"
attributes:
class: data_row invoice_item
elements:
- type: Hidden
name: ivi_id
- type: Block
attributes:
class: ivi_desc
elements:
- type: Text
name: ivi_desc
size: 75
- type: Block
attributes:
class: ivi_unit_price numeric
elements:
- type: Text
name: ivi_unit_price
size: 8
- type: Block
attributes:
class: ivi_quantity numeric
elements:
- type: Text
name: ivi_quantity
size: 5
- type: Block
attributes:
class: ivi_total_price numeric
elements:
- type: "+Coatesoft::FormFu::Element::DataLabel"
name: ivi_total_price
- type: Block
attributes:
class: ivi_account
elements:
- type: Select
name: ivi_account
model_config:
resultset: Accounts
id_column: acc_id
label_column: acc_title
- type: Block
attributes:
class: ivi_item
elements:
- type: Select
name: ivi_item
empty_first: 1
empty_first_label: <no inventory item>
model_config:
resultset: Items
id_column: itm_id
label_column: itm_description
- type: Block
attributes:
class: ivi_tax_type
elements:
- type: Select
name: ivi_tax_type
empty_first: 1
empty_first_label: <no tax>
model_config:
resultset: Taxes
id_column: tax_id
label_column: tax_desc
- type: Block
attributes:
class: ivi_memo
elements:
- type: Text
name: ivi_memo
size: 100
And here's the relevant part of my Catalyst controller:
sub edit :Local :FormConfig('invoices/edit_invoice.yml') {
my ($self, $c, $ivc_id) = @_;
if ($c->request->param('cancel')) {
$c->response->redirect($c->uri_for("/invoices"));
$c->detach();
}
my $invoice = ($ivc_id) ? $c->model('DB::Invoices')->find($ivc_id)
: $c->model('DB::Invoices')->new_result({});
my $form = $c->stash->{form};
if ($form->submitted_and_valid()) {
$form->process();
$form->model->update($invoice);
if (! $c->request->param('draft')) {
# Save to accounts
}
$c->response->redirect($c->uri_for("/invoices"));
$c->detach();
}
}
Any ideas, folks?
Thanks,
Greg Coates
Coatesoft
_______________________________________________
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
_______________________________________________
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