1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
use strict;
use warnings;
use Test::More tests => 4;
use HTML::FormFu;
my $form = HTML::FormFu->new(
{ tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } );
$form->load_config_file('t/elements/text_layout.yml');
###
is( $form, <<HTML, 'default layout' );
<form action="" id="form" method="post">
<div>
<label for="form_foo">Foo</label>
<input name="foo" type="text" id="form_foo" />
<span>
The foo
</span>
</div>
</form>
HTML
my $foo = $form->get_field( { name => 'foo' } );
###
$foo->layout( { label => [ 'field', 'label_text', ], } );
is( $form, <<HTML, 'label tag contains both input tag and label text' );
<form action="" id="form" method="post">
<div>
<label for="form_foo">
<input name="foo" type="text" id="form_foo" />
Foo
</label>
</div>
</form>
HTML
###
$foo->layout(
[ 'label',
{ div => {
attributes => { class => 'xxx' },
content => 'field'
},
},
] );
is( $form, <<HTML, 'arbitrary div with attributes containing input tag' );
<form action="" id="form" method="post">
<div>
<label for="form_foo">Foo</label>
<div class="xxx">
<input name="foo" type="text" id="form_foo" />
</div>
</div>
</form>
HTML
###
$foo->layout(
{ div => {
attributes => { class => 'xxx', },
content => {
div => {
attributes => { class => 'yyy', },
content => { label => [ 'field', 'label_text', ], },
},
},
},
} );
is( $form,
<<HTML, '2 nested arbitrary divs with attributes, containing label tag containing input tag and label text' );
<form action="" id="form" method="post">
<div>
<div class="xxx">
<div class="yyy">
<label for="form_foo">
<input name="foo" type="text" id="form_foo" />
Foo
</label>
</div>
</div>
</div>
</form>
HTML
|