At the moment, the 'new_empty_row' option only allows you to add 1 new row.
Yes, supporting more than 1 row would be good.
First off, you could test whether it works by deleting line 383 from
lib/HTML/FormFu/Model/DBIC.pm
- it's the line that reads "&& $i == $max"

I think though, that this new behaviour should be off by default, with
a new option to switch it on.
I wondering whether this option's value should be a number, that can
control the maximum allowed number of new rows?

Carl

Hi Carl,

your fix worked for me. make test is still ok.
I attached all changes and the test (with a constraint for count):

Index: /Users/mo/Documents/workspace/HTML-FormFu-Model-DBIC/lib/HTML/ FormFu/Model/DBIC.pm
===================================================================
--- /Users/mo/Documents/workspace/HTML-FormFu-Model-DBIC/lib/HTML/ FormFu/Model/DBIC.pm (revision 998) +++ /Users/mo/Documents/workspace/HTML-FormFu-Model-DBIC/lib/HTML/ FormFu/Model/DBIC.pm (working copy)

@@ -380,7 +379,7 @@
         my $row;

         if (   ( !defined $value || $value eq '' )
-            && $i == $max
+            #&& $i == $max
             && $block->model_config->{DBIC}{new_empty_row} )
         {


update/has_many_repeatable_many_new.t
----

use strict;
use warnings;
use Test::More tests => 7;

use HTML::FormFu;
use lib qw(t/lib lib);
use DBICTestLib 'new_db';
use MySchema;

new_db();

my $form = HTML::FormFu->new;

$form->load_config_file('t/update/has_many_repeatable_many_new.yml');

my $schema = MySchema->connect('dbi:SQLite:dbname=t/test.db');

my $user_rs    = $schema->resultset('User');
my $address_rs = $schema->resultset('Address');

{
        my $rep = $form->get_all_element({nested_name => "addresses"});
        $form->process( {
            'id'                  => '',
            'name'                => 'new nick',
            'count'               => 2,
            'addresses.id_1'      => '',
            'addresses.address_1' => 'new home',
            'addresses.id_2'      => '',
            'addresses.address_2' => 'new office',
        } );
$rep->repeat(2);

    ok( $form->submitted_and_valid );

    my $row = $user_rs->new({});

    $form->model('DBIC')->update($row);

    my $user = $user_rs->find(1);

    is( $user->name, 'new nick' );

    my @add = $user->addresses->all;

    is( scalar @add, 2 );

    is( $add[0]->id,      1 );
    is( $add[0]->address, 'new home' );

    is( $add[1]->id,      2 );
    is( $add[1]->address, 'new office' );
}


update/has_many_repeatable_many_new.yml
----

---
auto_fieldset: 1

elements:
  - type: Hidden
    name: id

  - type: Text
    name: name

  - type: Repeatable
    nested_name: addresses
    counter_name: count
    model_config:
      DBIC:
        new_empty_row: address

    elements:
      - type: Hidden
        name: id

      - type: Text
        name: address

  - type: Hidden
    name: count
    constraints:
      - type: Range
        max: 2

  - type: Submit
    name: submit




_______________________________________________
HTML-FormFu mailing list
[email protected]
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu

Reply via email to