use strict;
use warnings;
use Test::More tests => 44;
use HTML::FormFu;
use HTML::FormFu::Model::HashRef;
my %test = (
'name_2' => 'name_2',
'name_bar_foo' => 'name\\_bar\\_foo',
'name_2_bar' => 'name\\_2\\_bar',
'name_2.bar' => 'name_2.bar'
);
while ( my ( $k, $v ) = each %test ) {
is( HTML::FormFu::Model::HashRef::_escape_name($k), $v );
}
is( HTML::FormFu::Model::HashRef::_unescape_name('foo\\_bar'), 'foo_bar' );
my $form = HTML::FormFu->new(
{ tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } );
$form->element('Checkbox')->name('bar')->value('y');
$form->auto_fieldset(1);
$form->default_model('HashRef');
$form->populate(
{
elements => [
{
type => "DateTime",
name => "datetime",
auto_inflate => 1,
year => { list => [1999] }
},
{
name => "inflator",
deflator => { type => 'Strftime', strftime => '%F %H:%M' },
inflator =>
{ type => "DateTime", parser => { strptime => '%F' } }
},
{
type => "Repeatable",
nested_name => "many",
elements => [
{ name => "id" },
{
type => "Block",
name => "nested",
elements => [ { type => "Text", name => "foo" } ]
}
]
},
{
type => "Select",
name => "single-select",
options => [ [qw(1 foo)], [qw(2 bar)] ]
},
{
type => "Select",
name => "multi-select",
options => [ [qw(1 foo)], [qw(2 bar)] ]
},
{
type => "Block",
nested_name => "nested",
elements => [ { type => "Text", name => "foo" } ]
},
{
type => "Multi",
name => "address",
elements => [ { name => "street" }, { name => "number" } ]
},
{
type => "Multi",
name => "address-split",
elements => [ { name => "street" }, { name => "number" } ],
deflators => [ { type => "CompoundSplit" } ]
},
{
type => "SimpleTable",
rows => [ [ { name => "table1" } ] ]
}
]
}
);
for ( 0 .. 1 ) {
$form->auto_fieldset($_);
$form->model->default_values(
{
datetime => '30-08-1999 22:00',
bar => 'y',
many => [ { id => 1, foo => "bar" }, { id => 2, foo => "baz" } ],
'single-select' => 1,
'inflator' => '2008-09-22',
'multi-select' => [ 1, 2 ],
nested => { foo => "bar" },
address => { street => "Lombardstreet", number => 22 },
'address-split' => "Lombardstreet 22",
table1 => "test"
}
);
$form->process;
like( $form->get_field('datetime_minute'),
qr/