File: inlinecheckboxes.t

package info (click to toggle)
libhtml-formhandler-perl 0.40057-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,320 kB
  • ctags: 685
  • sloc: perl: 8,849; makefile: 2
file content (69 lines) | stat: -rw-r--r-- 1,834 bytes parent folder | download
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
use strict;
use warnings;
use Test::More;
use HTML::FormHandler::Test;

{
    package MyApp::Form::Test;
    use HTML::FormHandler::Moose;
    extends 'HTML::FormHandler';

    has '+widget_wrapper' => ( default => 'Bootstrap3');
	sub build_form_tags {{
	'layout_classes' => {
		label_class => ['col-lg-2'],
		element_wrapper_class => ['col-lg-10'],
		no_label_element_wrapper_class => ['col-lg-offset-2'],
	},
    }}
	has_field 'Checkboxes' => (
        type => 'Compound',
        do_wrapper => 1,
        do_label => 1,
	);
	has_field 'Checkboxes.option1' => (
        type => 'Checkbox',
        do_wrapper => 0,
        do_label => 0,
        tags => { 'inline' => 1 },
	);
	has_field 'Checkboxes.option2' => (
        type => 'Checkbox',
        do_wrapper => 0,
        do_label => 0,
        tags => { 'inline' => 1 },
	);
	has_field 'Checkboxes.option3' => (
        type => 'Checkbox',
        do_wrapper => 0,
        do_label => 0,
        tags => { 'inline' => 1 },
	);
}

my $form = MyApp::Form::Test->new;
$form->process;

my $expected = '
<div class="form-group" id="Checkboxes">
	<label class="col-lg-2 control-label" for="Checkboxes">Checkboxes</label>
	<div class="col-lg-10">
		<label class="checkbox-inline"  for="Checkboxes.option1">
			<input type="checkbox" name="Checkboxes.option1" id="Checkboxes.option1" value="1" />
			Option1
		</label>
		<label class="checkbox-inline"  for="Checkboxes.option2">
			<input type="checkbox" name="Checkboxes.option2" id="Checkboxes.option2" value="1" />
			Option2
		</label>
		<label class="checkbox-inline"  for="Checkboxes.option3">
			<input type="checkbox" name="Checkboxes.option3" id="Checkboxes.option3" value="1" />
			Option3
		</label>
	</div>
</div>
';

is_html( $form->field('Checkboxes')->render, $expected, 'inline checkboxes rendered ok' );

done_testing;