| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use Test::More; |
| 4 |
use HTML::FormHandler::Test; |
| 5 |
|
| 6 |
{ |
| 7 |
package MyApp::Form::InLine::Theme; |
| 8 |
use Moose::Role; |
| 9 |
|
| 10 |
# form tag classes |
| 11 |
sub build_form_element_class { ['well', 'form-search'] } |
| 12 |
# form wrapper class |
| 13 |
sub build_form_wrapper_class { ['span9'] } |
| 14 |
# turn on form wrapper, set the tag to 'div' (default is fieldset) |
| 15 |
sub build_do_form_wrapper {1} |
| 16 |
sub build_form_tags {{ |
| 17 |
wrapper_tag => 'div', |
| 18 |
before => |
| 19 |
'<h3>Inline form</h3> |
| 20 |
<div class="row"> |
| 21 |
<div class="span3"> |
| 22 |
<p>Inputs are block level to start. For <code>.form-inline</code> and <code>.form-horizontal</code>, we use inline-block.</p> |
| 23 |
</div>', |
| 24 |
after => '</div>', |
| 25 |
no_form_message_div => 1, |
| 26 |
}} |
| 27 |
# update individual fields |
| 28 |
sub build_update_subfields {{ |
| 29 |
email => { element_class => ['input-small'], element_attr => { placeholder => 'Email' } }, |
| 30 |
password => { element_class => ['input-small'], element_attr => { placeholder => 'Password' }, |
| 31 |
tags => { wrapper_tag => 0 } }, |
| 32 |
go => { element_class => ['btn'] }, |
| 33 |
}} |
| 34 |
|
| 35 |
} |
| 36 |
|
| 37 |
{ |
| 38 |
package MyApp::Form::InLine; |
| 39 |
use HTML::FormHandler::Moose; |
| 40 |
extends 'HTML::FormHandler'; |
| 41 |
with 'MyApp::Form::InLine::Theme'; |
| 42 |
|
| 43 |
has '+name' => ( default => 'inline_form' ); |
| 44 |
has '+widget_wrapper' => ( default => 'None' ); |
| 45 |
|
| 46 |
has_field 'email' => ( type => 'Email' ); |
| 47 |
has_field 'password' => ( type => 'Password' ); |
| 48 |
has_field 'go' => ( type => 'Submit', widget => 'ButtonTag', value => 'Go' ) |
| 49 |
} |
| 50 |
|
| 51 |
my $form = MyApp::Form::InLine->new; |
| 52 |
$form->process; |
| 53 |
my $rendered = $form->render; |
| 54 |
|
| 55 |
my $expected = '<h3>Inline form</h3> |
| 56 |
<div class="row"> |
| 57 |
<div class="span3"> |
| 58 |
<p>Inputs are block level to start. For <code>.form-inline</code> and <code>.form-horizontal</code>, we use inline-block.</p> |
| 59 |
</div> |
| 60 |
<div class="span9"> |
| 61 |
<form class="well form-search" id="inline_form" method="post"> |
| 62 |
<input type="text" class="input-small" placeholder="Email" name="email" id="email" value="" /> |
| 63 |
<input type="password" class="input-small" placeholder="Password" name="password" id="password" value="" /> |
| 64 |
<button type="submit" class="btn" name="go" id="go">Go</button> |
| 65 |
</form> |
| 66 |
</div> |
| 67 |
</div>'; |
| 68 |
|
| 69 |
is_html( $rendered, $expected, 'form renders correctly' ); |
| 70 |
|
| 71 |
done_testing; |