| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use Test::More; |
| 4 |
use HTML::FormHandler::Test; |
| 5 |
|
| 6 |
{ |
| 7 |
package HTML::FormHandler::Render::FFTheme; |
| 8 |
use Moose::Role; |
| 9 |
|
| 10 |
sub build_update_subfields {{ all => { tags => { no_wrapped_label => 1 } } }} |
| 11 |
sub html_attributes { |
| 12 |
my ( $self, $field, $type, $attr ) = @_; |
| 13 |
my $class = $attr->{class} || []; |
| 14 |
if( $type eq 'wrapper' ) { |
| 15 |
# this is not exactly like what FF does, but it's close |
| 16 |
push @$class, $field->type_attr; |
| 17 |
push @$class, 'label' if $field->do_label; |
| 18 |
$attr->{class} = $class; |
| 19 |
} |
| 20 |
return $attr; |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
{ |
| 25 |
package Test::Form; |
| 26 |
use HTML::FormHandler::Moose; |
| 27 |
extends 'HTML::FormHandler'; |
| 28 |
with 'HTML::FormHandler::Render::FFTheme'; |
| 29 |
|
| 30 |
has '+name' => ( default => 'test_form' ); |
| 31 |
has '+action' => ( default => '/form' ); |
| 32 |
has_field 'user' => ( label => 'Username' ); |
| 33 |
has_field 'pass' => ( type => 'Password', label => 'Password' ); |
| 34 |
has_field 'opt_in' => ( type => 'Checkbox', |
| 35 |
label => 'Opt in?', |
| 36 |
); |
| 37 |
has_field 'choose' => ( type => 'Select', |
| 38 |
label => 'Choose some', |
| 39 |
options => [ { label => 'blue', value => 1 }, { label => 'red', value => 2 }] ); |
| 40 |
has_field 'submit' => ( type => 'Submit', value => "Save" ); |
| 41 |
|
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
my $expected = |
| 46 |
'<form action="/form" method="post" id="test_form" > |
| 47 |
<div class="form_messages"></div> |
| 48 |
<div class="text label"> |
| 49 |
<label for="user">Username</label> |
| 50 |
<input name="user" type="text" id="user" value="" /> |
| 51 |
</div> |
| 52 |
<div class="password label"> |
| 53 |
<label for="pass">Password</label> |
| 54 |
<input name="pass" id="pass" type="password" value="" /> |
| 55 |
</div> |
| 56 |
<div class="checkbox label"> |
| 57 |
<label for="opt_in">Opt in?</label> |
| 58 |
<input name="opt_in" id="opt_in" type="checkbox" value="1" /> |
| 59 |
</div> |
| 60 |
<div class="select label"> |
| 61 |
<label for="choose">Choose some</label> |
| 62 |
<select name="choose" id="choose"> |
| 63 |
<option id="choose.0" value="1">blue</option> |
| 64 |
<option id="choose.1" value="2">red</option> |
| 65 |
</select> |
| 66 |
</div> |
| 67 |
<div class="submit"> |
| 68 |
<input name="submit" id="submit" type="submit" value="Save" /> |
| 69 |
</div> |
| 70 |
</form>'; |
| 71 |
|
| 72 |
my $form = Test::Form->new; |
| 73 |
$form->process; |
| 74 |
my $rendered = $form->render; |
| 75 |
is_html($rendered, $expected, 'renders ok' ); |
| 76 |
|
| 77 |
done_testing; |