use strict; use warnings; use Test::More; use HTML::FormFu; my @options = ( [ '1' => 'One' ], [ '2' => 'Two' ], [ '3' => 'Three' ] ); my $defaults = { items => [ { sel => '1' }, { sel => '2' }, { sel => '3' }, ] }; # these 2 are the same, except the second includes the options my $options_form_hash = { action => '/foo/bar', id => 'form', auto_id => '%n', elements => [ { type => 'Hidden', name => 'item_count' }, { type => 'Repeatable', nested_name => 'items', counter_name => 'item_count', elements => [ { type => 'Select', name => 'sel' } ] } ] }; my $basic_form_hash = { action => '/foo/bar', id => 'form', auto_id => '%n', elements => [ { type => 'Hidden', name => 'item_count' }, { type => 'Repeatable', nested_name => 'items', counter_name => 'item_count', elements => [ { type => 'Select', name => 'sel', options => \@options } ] } ] }; # form - single step - load config in one go, process my $form_1 = HTML::FormFu->new( { default_model => 'HashRef' } ); ok( $form_1, 'Build initial form with options' ); $form_1->populate($options_form_hash); $form_1->model->default_values($defaults); $form_1->process; my $form_1_xhtml = $form_1->render; # form - multi process - load, do stuff, process, change it, process my $form_2 = HTML::FormFu->new( { default_model => 'HashRef' } ); ok( $form_2, 'Build initial form without options, then add them' ); $form_2->populate($basic_form_hash); $form_2->get_field( { name => 'sel' } )->options( [@options] ); $form_2->process; $form_2->model->default_values($defaults); my $form_2_xhtml = $form_2->render; # compare these things... is( $form_1_xhtml, $form_2_xhtml, 'Compare render of 2 forms' ); #diag($form_2_xhtml); done_testing();