[html-formfu] Repeatable save problems

Gerg Coates greg at coatesoft.com
Sun Apr 26 23:02:24 GMT 2009


I have a form that contains a repeatable block that I'm using with 
Catalyst.  For some reason, the items in the child table aren't getting 
saved along with the rest of the data.  I've scoured the documentation, 
and as far as I can tell, I have all of the necessary bits in place.

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();
   }
}

Does anyone see anything that I might be missing?  Is the fact that my 
form elements are inside Block elements causing problems?

Thanks,
Greg Coates
Coatesoft



More information about the HTML-FormFu mailing list