| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use Test::More; |
| 4 |
use HTML::FormHandler::Test; |
| 5 |
|
| 6 |
{ |
| 7 |
package MyApp::Form::ExtControls; |
| 8 |
use HTML::FormHandler::Moose; |
| 9 |
extends 'HTML::FormHandler'; |
| 10 |
with 'HTML::FormHandler::Widget::Theme::Bootstrap'; |
| 11 |
|
| 12 |
sub build_form_tags {{ |
| 13 |
after_start => "<fieldset>\n<legend>Extending form controls</legend>", |
| 14 |
}} |
| 15 |
sub build_process_list { ['form_sizes', 'prependedInput', 'appendedInput', 'inlineCheckboxes', |
| 16 |
'checkboxList'] } |
| 17 |
has_block 'form_sizes' => ( type => 'Bootstrap', render_list => ['text1', 'text2', 'text3'], |
| 18 |
label => 'Form sizes', |
| 19 |
after_controls => '<p class="help-block">Use the same <code>.span*</code> classes from the grid system for input sizes.</p>', |
| 20 |
); |
| 21 |
# these three fields are in the 'form_sizes' block |
| 22 |
has_field 'text1' => ( widget_wrapper => 'None', element_class => ['span2'], |
| 23 |
element_attr => { placeholder => '.span2' } ); |
| 24 |
has_field 'text2' => ( widget_wrapper => 'None', element_class => ['span3'], |
| 25 |
element_attr => { placeholder => '.span3' } ); |
| 26 |
has_field 'text3' => ( widget_wrapper => 'None', element_class => ['span4'], |
| 27 |
element_attr => { placeholder => '.span4' } ); |
| 28 |
|
| 29 |
has_field 'prependedInput' => ( label => 'Prepended text', size => 16, element_class => ['span2'], |
| 30 |
tags => { input_prepend => '@', after_element => '<p class="help-block">Here\'s some help text</p>' } |
| 31 |
); |
| 32 |
has_field 'appendedInput' => ( label => 'Appended text', size => 16, element_class => ['span2'], |
| 33 |
tags => { input_append => '.00', after_element => '<p class="help-block">Here\'s more help text</p>' } |
| 34 |
); |
| 35 |
has_field 'appendedPrependedInput' => ( label => 'Append and prepend', size => 16, element_class => ['span2'], |
| 36 |
tags => { input_append => '.00', input_prepend => '$' }, |
| 37 |
); |
| 38 |
has_field 'appendedInputButton' => ( label => 'Append with button', size => 16, element_class => ['span2'], |
| 39 |
tags => { input_append_button => 'Go!' }, |
| 40 |
); |
| 41 |
has_field 'appendedInputButtons' => ( label => 'Two-button append', size => 16, element_class => ['span2'], |
| 42 |
tags => { input_append_button => ['Search', 'Options'] }, |
| 43 |
); |
| 44 |
|
| 45 |
has_field 'inlineCheckboxes' => ( type => 'Multiple', widget => 'CheckboxGroup', |
| 46 |
label => 'Inline checkboxes', |
| 47 |
tags => { inline => 1 }, options => [ { value => 'option1', label => '1' }, |
| 48 |
{ value => 'option2', label => '2' }, { value => 'option3', label => '3' } ], |
| 49 |
); |
| 50 |
|
| 51 |
has_block 'checkboxList' => ( type => 'Bootstrap', label => 'Checkboxes', |
| 52 |
render_list => ['optionsCheckboxList1', 'optionsCheckboxList2', 'optionsCheckboxList3' ], |
| 53 |
after_controls => '<p class="help-text"><strong>Note:</strong> Labels surround all the options for much larger click areas and a more usable form.</p>' |
| 54 |
); |
| 55 |
has_field 'optionsCheckboxList1' => ( type => 'Checkbox', do_wrapper => 0, do_label => 0, |
| 56 |
checkbox_value => 'option1', |
| 57 |
option_label => 'Option one is this and that—be sure to include why it’s great', |
| 58 |
); |
| 59 |
has_field 'optionsCheckboxList2' => ( type => 'Checkbox', do_wrapper => 0, do_label => 0, |
| 60 |
checkbox_value => 'option2', |
| 61 |
option_label => 'Option two can also be checked and included in form results', |
| 62 |
); |
| 63 |
has_field 'optionsCheckboxList3' => ( type => 'Checkbox', do_wrapper => 0, do_label => 0, |
| 64 |
checkbox_value => 'option3', |
| 65 |
option_label => 'Option three can—yes, you guessed it—also be checked and included in form results', |
| 66 |
); |
| 67 |
|
| 68 |
has_field 'optionsRadios' => ( type => 'Multiple', widget => 'RadioGroup', |
| 69 |
label => 'Radio buttons', |
| 70 |
options => [ |
| 71 |
{ value => 'option1', label => 'Option one is this and that—be sure to include why it’s great' }, |
| 72 |
{ value => 'option2', label => 'Option two can is something else and selecting it will deselect option one' }, |
| 73 |
] |
| 74 |
); |
| 75 |
} |
| 76 |
|
| 77 |
my $form = MyApp::Form::ExtControls->new; |
| 78 |
ok( $form, 'form built' ); |
| 79 |
$form->process; |
| 80 |
my $expected = |
| 81 |
'<div class="control-group"> |
| 82 |
<label class="control-label">Form sizes</label> |
| 83 |
<div class="controls"> |
| 84 |
<input id="text1" name="text1" class="span2" type="text" placeholder=".span2" value="" /> |
| 85 |
<input id="text2" name="text2" class="span3" type="text" placeholder=".span3" value="" /> |
| 86 |
<input id="text3" name="text3" class="span4" type="text" placeholder=".span4" value="" /> |
| 87 |
<p class="help-block">Use the same <code>.span*</code> classes from the grid system for input sizes.</p> |
| 88 |
</div> |
| 89 |
</div>'; |
| 90 |
my $rendered = $form->block('form_sizes')->render; |
| 91 |
is_html( $rendered, $expected, 'form_sizes block rendered ok' ); |
| 92 |
|
| 93 |
$expected = |
| 94 |
' |
| 95 |
<div class="control-group"> |
| 96 |
<label class="control-label" for="prependedInput">Prepended text</label> |
| 97 |
<div class="controls"> |
| 98 |
<div class="input-prepend"> |
| 99 |
<span class="add-on">@</span><input class="span2" id="prependedInput" name="prependedInput" size="16" type="text" value="" /> |
| 100 |
</div> |
| 101 |
<p class="help-block">Here\'s some help text</p> |
| 102 |
</div> |
| 103 |
</div>'; |
| 104 |
$rendered = $form->field('prependedInput')->render; |
| 105 |
is_html( $rendered, $expected, 'prependedInput rendered ok' ); |
| 106 |
|
| 107 |
$expected = |
| 108 |
'<div class="control-group"> |
| 109 |
<label class="control-label" for="appendedInput">Appended text</label> |
| 110 |
<div class="controls"> |
| 111 |
<div class="input-append"> |
| 112 |
<input class="span2" id="appendedInput" name="appendedInput" size="16" type="text" value="" /><span class="add-on">.00</span> |
| 113 |
</div> |
| 114 |
<p class="help-block">Here\'s more help text</p> |
| 115 |
</div> |
| 116 |
</div>'; |
| 117 |
$rendered = $form->field('appendedInput')->render; |
| 118 |
is_html( $rendered, $expected, 'appendedinput rendered ok' ); |
| 119 |
|
| 120 |
$expected = |
| 121 |
'<div class="control-group"> |
| 122 |
<label class="control-label" for="appendedPrependedInput">Append and prepend</label> |
| 123 |
<div class="controls"> |
| 124 |
<div class="input-prepend input-append"> |
| 125 |
<span class="add-on">$</span><input class="span2" id="appendedPrependedInput" name="appendedPrependedInput" size="16" type="text" value="" /><span class="add-on">.00</span> |
| 126 |
</div> |
| 127 |
</div>'; |
| 128 |
$rendered = $form->field('appendedPrependedInput')->render; |
| 129 |
is_html( $rendered, $expected, 'appendedPrependedInput rendered ok' ); |
| 130 |
|
| 131 |
$expected = |
| 132 |
'<div class="control-group"> |
| 133 |
<label class="control-label" for="appendedInputButton">Append with button</label> |
| 134 |
<div class="controls"> |
| 135 |
<div class="input-append"> |
| 136 |
<input class="span2" id="appendedInputButton" name="appendedInputButton" size="16" type="text" value="" /><button class="btn" type="button">Go!</button> |
| 137 |
</div> |
| 138 |
</div> |
| 139 |
</div>'; |
| 140 |
$rendered = $form->field('appendedInputButton')->render; |
| 141 |
is_html( $rendered, $expected, 'appendedInputButton rendered ok' ); |
| 142 |
|
| 143 |
$expected = |
| 144 |
'<div class="control-group"> |
| 145 |
<label class="control-label" for="appendedInputButtons">Two-button append</label> |
| 146 |
<div class="controls"> |
| 147 |
<div class="input-append"> |
| 148 |
<input class="span2" id="appendedInputButtons" name="appendedInputButtons" size="16" type="text" value="" /><button class="btn" type="button">Search</button><button class="btn" type="button">Options</button> |
| 149 |
</div> |
| 150 |
</div> |
| 151 |
</div>'; |
| 152 |
$rendered = $form->field('appendedInputButtons')->render; |
| 153 |
is_html( $rendered, $expected, 'appendedInputButtons rendered ok' ); |
| 154 |
|
| 155 |
$expected = |
| 156 |
'<div class="control-group"> |
| 157 |
<label class="control-label" for="inlineCheckboxes">Inline checkboxes</label> |
| 158 |
<div class="controls"> |
| 159 |
<label class="checkbox inline" for="inlineCheckboxes.0"> |
| 160 |
<input type="checkbox" id="inlineCheckboxes.0" name="inlineCheckboxes" value="option1"> 1 |
| 161 |
</label> |
| 162 |
<label class="checkbox inline" for="inlineCheckboxes.1"> |
| 163 |
<input type="checkbox" id="inlineCheckboxes.1" name="inlineCheckboxes" value="option2"> 2 |
| 164 |
</label> |
| 165 |
<label class="checkbox inline" for="inlineCheckboxes.2"> |
| 166 |
<input type="checkbox" id="inlineCheckboxes.2" name="inlineCheckboxes" value="option3"> 3 |
| 167 |
</label> |
| 168 |
</div> |
| 169 |
</div>'; |
| 170 |
$rendered = $form->field('inlineCheckboxes')->render; |
| 171 |
is_html( $rendered, $expected, 'inlineCheckboxes rendered ok' ); |
| 172 |
|
| 173 |
$expected = |
| 174 |
'<label class="checkbox" for="optionsCheckboxList1"> |
| 175 |
<input type="checkbox" name="optionsCheckboxList1" id="optionsCheckboxList1" value="option1"> |
| 176 |
Option one is this and that—be sure to include why it’s great |
| 177 |
</label>'; |
| 178 |
$rendered = $form->field('optionsCheckboxList1')->render; |
| 179 |
is_html( $rendered, $expected, 'optionsCheckboxList1 rendered ok by itself'); |
| 180 |
|
| 181 |
$expected = |
| 182 |
'<div class="control-group"> |
| 183 |
<label class="control-label">Checkboxes</label> |
| 184 |
<div class="controls"> |
| 185 |
<label class="checkbox" for="optionsCheckboxList1"> |
| 186 |
<input type="checkbox" name="optionsCheckboxList1" id="optionsCheckboxList1" value="option1"> |
| 187 |
Option one is this and that—be sure to include why it’s great |
| 188 |
</label> |
| 189 |
<label class="checkbox" for="optionsCheckboxList2"> |
| 190 |
<input type="checkbox" name="optionsCheckboxList2" id="optionsCheckboxList2" value="option2"> |
| 191 |
Option two can also be checked and included in form results |
| 192 |
</label> |
| 193 |
<label class="checkbox" for="optionsCheckboxList3"> |
| 194 |
<input type="checkbox" name="optionsCheckboxList3" id="optionsCheckboxList3" value="option3"> |
| 195 |
Option three can—yes, you guessed it—also be checked and included in form results |
| 196 |
</label> |
| 197 |
<p class="help-text"><strong>Note:</strong> Labels surround all the options for much larger click areas and a more usable form.</p> |
| 198 |
</div> |
| 199 |
</div>'; |
| 200 |
$rendered = $form->block('checkboxList')->render; |
| 201 |
is_html( $rendered, $expected, 'checkbox group block renders ok' ); |
| 202 |
|
| 203 |
$expected = |
| 204 |
'<div class="control-group"> |
| 205 |
<label class="control-label" for="optionsRadios">Radio buttons</label> |
| 206 |
<div class="controls"> |
| 207 |
<label class="radio" for="optionsRadios.0"> |
| 208 |
<input type="radio" name="optionsRadios" id="optionsRadios.0" value="option1" /> |
| 209 |
Option one is this and that—be sure to include why it’s great |
| 210 |
</label> |
| 211 |
<label class="radio" for="optionsRadios.1"> |
| 212 |
<input type="radio" name="optionsRadios" id="optionsRadios.1" value="option2" /> |
| 213 |
Option two can is something else and selecting it will deselect option one |
| 214 |
</label> |
| 215 |
</div> |
| 216 |
</div>'; |
| 217 |
$rendered = $form->field('optionsRadios')->render; |
| 218 |
is_html( $rendered, $expected, 'radio rendered ok' ); |
| 219 |
|
| 220 |
$expected = |
| 221 |
'<div class="row"> |
| 222 |
<div class="span8"> |
| 223 |
<form class="form-horizontal"> |
| 224 |
<fieldset> |
| 225 |
<legend>Extending form controls</legend> |
| 226 |
<div class="control-group"> |
| 227 |
<label class="control-label">Form sizes</label> |
| 228 |
<div class="controls"> |
| 229 |
<input id="text1" name="text1" class="span2" type="text" placeholder=".span2" value="" /> |
| 230 |
<input id="text2" name="text2" class="span3" type="text" placeholder=".span3" value="" /> |
| 231 |
<input id="text3" name="text3" class="span4" type="text" placeholder=".span4" value="" /> |
| 232 |
<p class="help-block">Use the same <code>.span*</code> classes from the grid system for input sizes.</p> |
| 233 |
</div> |
| 234 |
</div> |
| 235 |
<div class="control-group"> |
| 236 |
<label class="control-label" for="prependedInput">Prepended text</label> |
| 237 |
<div class="controls"> |
| 238 |
<div class="input-prepend"> |
| 239 |
<span class="add-on">@</span><input class="span2" id="prependedInput" name="prependedInput" size="16" type="text" value="" /> |
| 240 |
</div> |
| 241 |
<p class="help-block">Here\'s some help text</p> |
| 242 |
</div> |
| 243 |
</div> |
| 244 |
<div class="control-group"> |
| 245 |
<label class="control-label" for="appendedInput">Appended text</label> |
| 246 |
<div class="controls"> |
| 247 |
<div class="input-append"> |
| 248 |
<input class="span2" id="appendedInput" name="appendedInput" size="16" type="text" value="" /><span class="add-on">.00</span> |
| 249 |
</div> |
| 250 |
<p class="help-block">Here\'s more help text</p> |
| 251 |
</div> |
| 252 |
</div> |
| 253 |
<div class="control-group"> |
| 254 |
<label class="control-label" for="inlineCheckboxes">Inline checkboxes</label> |
| 255 |
<div class="controls"> |
| 256 |
<label class="checkbox inline" for="inlineCheckboxes.0"> |
| 257 |
<input type="checkbox" id="inlineCheckboxes.0" name="inlineCheckboxes" value="option1"> 1 |
| 258 |
</label> |
| 259 |
<label class="checkbox inline" for="inlineCheckboxes.1"> |
| 260 |
<input type="checkbox" id="inlineCheckboxes.1" name="inlineCheckboxes" value="option2"> 2 |
| 261 |
</label> |
| 262 |
<label class="checkbox inline" for="inlineCheckboxes.2"> |
| 263 |
<input type="checkbox" id="inlineCheckboxes.2" name="inlineCheckboxes" value="option3"> 3 |
| 264 |
</label> |
| 265 |
</div> |
| 266 |
</div> |
| 267 |
<div class="control-group"> |
| 268 |
<label class="control-label">Checkboxes</label> |
| 269 |
<div class="controls"> |
| 270 |
<label class="checkbox" for="optionsCheckboxList1"> |
| 271 |
<input type="checkbox" name="optionsCheckboxList1" id="optionsCheckboxList1" value="option1"> |
| 272 |
Option one is this and that—be sure to include why it’s great |
| 273 |
</label> |
| 274 |
<label class="checkbox" for="optionsCheckboxList2"> |
| 275 |
<input type="checkbox" name="optionsCheckboxList2" id="optionsCheckboxList2" value="option2"> |
| 276 |
Option two can also be checked and included in form results |
| 277 |
</label> |
| 278 |
<label class="checkbox" for="optionsCheckboxList3"> |
| 279 |
<input type="checkbox" name="optionsCheckboxList3" id="optionsCheckboxList3" value="option3"> |
| 280 |
Option three can—yes, you guessed it—also be checked and included in form results |
| 281 |
</label> |
| 282 |
<p class="help-text"><strong>Note:</strong> Labels surround all the options for much larger click areas and a more usable form.</p> |
| 283 |
</div> |
| 284 |
</div> |
| 285 |
<div class="control-group"> |
| 286 |
<label class="control-label" for="optionsRadios">Radio buttons</label> |
| 287 |
<div class="controls"> |
| 288 |
<label class="radio" for="optionsRadios.0"> |
| 289 |
<input type="radio" name="optionsRadios" id="optionsRadios.0" value="option1" /> |
| 290 |
Option one is this and that—be sure to include why it’s great |
| 291 |
</label> |
| 292 |
<label class="radio" for="optionsRadios.1"> |
| 293 |
<input type="radio" name="optionsRadios" id="optionsRadios.1" value="option2" /> |
| 294 |
Option two can is something else and selecting it will deselect option one |
| 295 |
</label> |
| 296 |
</div> |
| 297 |
</div> |
| 298 |
<div class="form-actions"> |
| 299 |
<button type="submit" class="btn btn-primary">Save changes</button> |
| 300 |
<button type="reset" class="btn">Cancel</button> |
| 301 |
</div> |
| 302 |
</fieldset> |
| 303 |
</form> |
| 304 |
</div> |
| 305 |
</div>'; |
| 306 |
|
| 307 |
done_testing; |