Index: t/default_values/has_many_repeatable_select.yml =================================================================== --- t/default_values/has_many_repeatable_select.yml (revision 0) +++ t/default_values/has_many_repeatable_select.yml (revision 0) @@ -0,0 +1,25 @@ +--- +auto_fieldset: 1 + +elements: + - type: Hidden + name: id + + - type: Text + name: name + + - type: Repeatable + nested_name: user_bands + counter_name: count + + elements: + - type: Select + name: band + model_config: + resultset: Band + + - type: Hidden + name: count + + - type: Submit + name: submit Property changes on: t/default_values/has_many_repeatable_select.yml ___________________________________________________________________ Name: svn:keywords + "Author Date Id Revision Url" Name: svn:eol-style + native Index: t/default_values/has_many_repeatable_select.t =================================================================== --- t/default_values/has_many_repeatable_select.t (revision 0) +++ t/default_values/has_many_repeatable_select.t (revision 0) @@ -0,0 +1,72 @@ +use strict; +use warnings; +use Test::More tests => 6; + +use HTML::FormFu; +use lib 't/lib'; +use DBICTestLib 'new_db'; +use MySchema; +new_db(); + +my $form = HTML::FormFu->new; + +$form->load_config_file('t/default_values/has_many_repeatable_select.yml'); + +my $schema = MySchema->connect('dbi:SQLite:dbname=t/test.db'); + +$form->stash->{schema} = $schema; + +my $band_rs = $schema->resultset('Band'); +my $user_rs = $schema->resultset('User'); +my $userband_rs = $schema->resultset('UserBand'); +my $master = $schema->resultset('Master')->create( { id => 1 } ); + +# build a set of data in the db +{ + $band_rs->delete; + my @res = $band_rs->populate( + [ + { id => 1, band => 'First' }, + { id => 2, band => 'Second' }, + { id => 3, band => 'Third' }, + { id => 4, band => 'Fourth' }, + { id => 5, band => 'Fifth' }, + ] + ); +} +{ + $user_rs->delete; + my @res = $user_rs->populate( + [ { id => 1, master => 1, title => 'Mr', name => 'A First' }, ] ); +} +{ + $userband_rs->delete; + my @res = $userband_rs->populate( + [ { user => 1, band => 1 }, { user => 1, band => 3 }, ] ); +} + +# +# Get a single user from DB +# That user has 2 related user_band entries, so expect the form to +# have the initial user info, then 2 sub sections each with a select +# in.... +{ + my $row = $schema->resultset('User')->find(1); + + $form->model->default_values($row); + + is( $form->get_field('id')->default, '1' ); + is( $form->get_field('name')->default, 'A First' ); + is( $form->get_field('count')->default, '2' ); + + my $block = $form->get_all_element( { nested_name => 'user_bands' } ); + + my @reps = @{ $block->get_elements }; + + is( scalar @reps, 2 ); + + is( $reps[0]->get_field('band_1')->default, 1 ); + + is( $reps[1]->get_field('band_2')->default, 3 ); +} +