File: ext_controls.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 (307 lines) | stat: -rw-r--r-- 14,762 bytes parent folder | download | duplicates (5)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
use strict;
use warnings;
use Test::More;
use HTML::FormHandler::Test;

{
    package MyApp::Form::ExtControls;
    use HTML::FormHandler::Moose;
    extends 'HTML::FormHandler';
    with 'HTML::FormHandler::Widget::Theme::Bootstrap';

    sub build_form_tags {{
        after_start => "<fieldset>\n<legend>Extending form controls</legend>",
    }}
    sub build_process_list { ['form_sizes', 'prependedInput', 'appendedInput', 'inlineCheckboxes',
        'checkboxList'] }
    has_block 'form_sizes' => ( type => 'Bootstrap', render_list => ['text1', 'text2', 'text3'],
        label => 'Form sizes',
        after_controls => '<p class="help-block">Use the same <code>.span*</code> classes from the grid system for input sizes.</p>',
    );
    # these three fields are in the 'form_sizes' block
    has_field 'text1' => ( widget_wrapper => 'None', element_class => ['span2'],
        element_attr => { placeholder => '.span2' } );
    has_field 'text2' => ( widget_wrapper => 'None', element_class => ['span3'],
        element_attr => { placeholder => '.span3' } );
    has_field 'text3' => ( widget_wrapper => 'None', element_class => ['span4'],
        element_attr => { placeholder => '.span4' } );

    has_field 'prependedInput' => ( label => 'Prepended text', size => 16, element_class => ['span2'],
        tags => { input_prepend =>  '@', after_element => '<p class="help-block">Here\'s some help text</p>' }
    );
    has_field 'appendedInput' => ( label => 'Appended text', size => 16, element_class => ['span2'],
        tags => { input_append =>  '.00', after_element => '<p class="help-block">Here\'s more help text</p>' }
    );
    has_field 'appendedPrependedInput' => ( label => 'Append and prepend', size => 16, element_class => ['span2'],
        tags => { input_append =>  '.00', input_prepend => '$' },
    );
    has_field 'appendedInputButton' => ( label => 'Append with button', size => 16, element_class => ['span2'],
        tags => { input_append_button =>  'Go!' },
    );
    has_field 'appendedInputButtons' => ( label => 'Two-button append', size => 16, element_class => ['span2'],
        tags => { input_append_button =>  ['Search', 'Options'] },
    );

    has_field 'inlineCheckboxes' => ( type => 'Multiple', widget => 'CheckboxGroup',
        label => 'Inline checkboxes',
        tags => { inline => 1 }, options => [ { value => 'option1', label => '1' },
            { value => 'option2', label => '2' }, { value => 'option3', label => '3' } ],
    );

    has_block 'checkboxList' => ( type => 'Bootstrap', label => 'Checkboxes',
        render_list => ['optionsCheckboxList1', 'optionsCheckboxList2', 'optionsCheckboxList3' ],
        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>'
    );
    has_field 'optionsCheckboxList1' => ( type => 'Checkbox', do_wrapper => 0, do_label => 0,
        checkbox_value => 'option1',
        option_label => 'Option one is this and that—be sure to include why it’s great',
    );
    has_field 'optionsCheckboxList2' => ( type => 'Checkbox', do_wrapper => 0, do_label => 0,
        checkbox_value => 'option2',
        option_label => 'Option two can also be checked and included in form results',
    );
    has_field 'optionsCheckboxList3' => ( type => 'Checkbox', do_wrapper => 0, do_label => 0,
        checkbox_value => 'option3',
        option_label => 'Option three can—yes, you guessed it—also be checked and included in form results',
    );

    has_field 'optionsRadios' => ( type => 'Multiple', widget => 'RadioGroup',
        label => 'Radio buttons',
        options => [
            { value => 'option1', label => 'Option one is this and that—be sure to include why it’s great' },
            { value => 'option2', label => 'Option two can is something else and selecting it will deselect option one' },
        ]
    );
}

my $form = MyApp::Form::ExtControls->new;
ok( $form, 'form built' );
$form->process;
my $expected =
'<div class="control-group">
  <label class="control-label">Form sizes</label>
  <div class="controls">
    <input id="text1" name="text1" class="span2" type="text" placeholder=".span2" value="" />
    <input id="text2" name="text2" class="span3" type="text" placeholder=".span3" value="" />
    <input id="text3" name="text3" class="span4" type="text" placeholder=".span4" value="" />
    <p class="help-block">Use the same <code>.span*</code> classes from the grid system for input sizes.</p>
  </div>
</div>';
my $rendered = $form->block('form_sizes')->render;
is_html( $rendered, $expected, 'form_sizes block rendered ok' );

$expected =
'
<div class="control-group">
  <label class="control-label" for="prependedInput">Prepended text</label>
  <div class="controls">
    <div class="input-prepend">
      <span class="add-on">@</span><input class="span2" id="prependedInput" name="prependedInput" size="16" type="text" value="" />
    </div>
    <p class="help-block">Here\'s some help text</p>
  </div>
</div>';
$rendered = $form->field('prependedInput')->render;
is_html( $rendered, $expected, 'prependedInput rendered ok' );

$expected =
'<div class="control-group">
  <label class="control-label" for="appendedInput">Appended text</label>
  <div class="controls">
    <div class="input-append">
      <input class="span2" id="appendedInput" name="appendedInput" size="16" type="text" value="" /><span class="add-on">.00</span>
    </div>
    <p class="help-block">Here\'s more help text</p>
  </div>
</div>';
$rendered = $form->field('appendedInput')->render;
is_html( $rendered, $expected, 'appendedinput rendered ok' );

$expected =
'<div class="control-group">
  <label class="control-label" for="appendedPrependedInput">Append and prepend</label>
  <div class="controls">
    <div class="input-prepend input-append">
    <span class="add-on">$</span><input class="span2" id="appendedPrependedInput" name="appendedPrependedInput" size="16" type="text" value="" /><span class="add-on">.00</span>
  </div>
</div>';
$rendered = $form->field('appendedPrependedInput')->render;
is_html( $rendered, $expected, 'appendedPrependedInput rendered ok' );

$expected =
'<div class="control-group">
  <label class="control-label" for="appendedInputButton">Append with button</label>
  <div class="controls">
    <div class="input-append">
      <input class="span2" id="appendedInputButton" name="appendedInputButton" size="16" type="text" value="" /><button class="btn" type="button">Go!</button>
    </div>
  </div>
</div>';
$rendered = $form->field('appendedInputButton')->render;
is_html( $rendered, $expected, 'appendedInputButton rendered ok' );

$expected =
'<div class="control-group">
  <label class="control-label" for="appendedInputButtons">Two-button append</label>
  <div class="controls">
    <div class="input-append">
      <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>
    </div>
  </div>
</div>';
$rendered = $form->field('appendedInputButtons')->render;
is_html( $rendered, $expected, 'appendedInputButtons rendered ok' );

$expected =
'<div class="control-group">
  <label class="control-label" for="inlineCheckboxes">Inline checkboxes</label>
  <div class="controls">
    <label class="checkbox inline" for="inlineCheckboxes.0">
      <input type="checkbox" id="inlineCheckboxes.0" name="inlineCheckboxes" value="option1"> 1
    </label>
    <label class="checkbox inline" for="inlineCheckboxes.1">
      <input type="checkbox" id="inlineCheckboxes.1" name="inlineCheckboxes" value="option2"> 2
    </label>
    <label class="checkbox inline" for="inlineCheckboxes.2">
      <input type="checkbox" id="inlineCheckboxes.2" name="inlineCheckboxes" value="option3"> 3
    </label>
  </div>
</div>';
$rendered = $form->field('inlineCheckboxes')->render;
is_html( $rendered, $expected, 'inlineCheckboxes rendered ok' );

$expected =
'<label class="checkbox" for="optionsCheckboxList1">
  <input type="checkbox" name="optionsCheckboxList1" id="optionsCheckboxList1" value="option1">
  Option one is this and that&mdash;be sure to include why it’s great
</label>';
$rendered = $form->field('optionsCheckboxList1')->render;
is_html( $rendered, $expected, 'optionsCheckboxList1 rendered ok by itself');

$expected =
'<div class="control-group">
  <label class="control-label">Checkboxes</label>
  <div class="controls">
    <label class="checkbox" for="optionsCheckboxList1">
      <input type="checkbox" name="optionsCheckboxList1" id="optionsCheckboxList1" value="option1">
      Option one is this and that&mdash;be sure to include why it’s great
    </label>
    <label class="checkbox" for="optionsCheckboxList2">
      <input type="checkbox" name="optionsCheckboxList2" id="optionsCheckboxList2" value="option2">
      Option two can also be checked and included in form results
    </label>
    <label class="checkbox" for="optionsCheckboxList3">
      <input type="checkbox" name="optionsCheckboxList3" id="optionsCheckboxList3" value="option3">
      Option three can&mdash;yes, you guessed it&mdash;also be checked and included in form results
    </label>
    <p class="help-text"><strong>Note:</strong> Labels surround all the options for much larger click areas and a more usable form.</p>
  </div>
</div>';
$rendered = $form->block('checkboxList')->render;
is_html( $rendered, $expected, 'checkbox group block renders ok' );

$expected =
'<div class="control-group">
  <label class="control-label" for="optionsRadios">Radio buttons</label>
  <div class="controls">
    <label class="radio" for="optionsRadios.0">
      <input type="radio" name="optionsRadios" id="optionsRadios.0" value="option1" />
      Option one is this and that&mdash;be sure to include why it’s great
    </label>
    <label class="radio" for="optionsRadios.1">
      <input type="radio" name="optionsRadios" id="optionsRadios.1" value="option2" />
      Option two can is something else and selecting it will deselect option one
    </label>
  </div>
</div>';
$rendered = $form->field('optionsRadios')->render;
is_html( $rendered, $expected, 'radio rendered ok' );

$expected =
'<div class="row">
  <div class="span8">
    <form class="form-horizontal">
      <fieldset>
        <legend>Extending form controls</legend>
        <div class="control-group">
          <label class="control-label">Form sizes</label>
          <div class="controls">
            <input id="text1" name="text1" class="span2" type="text" placeholder=".span2" value="" />
            <input id="text2" name="text2" class="span3" type="text" placeholder=".span3" value="" />
            <input id="text3" name="text3" class="span4" type="text" placeholder=".span4" value="" />
            <p class="help-block">Use the same <code>.span*</code> classes from the grid system for input sizes.</p>
          </div>
        </div>
        <div class="control-group">
          <label class="control-label" for="prependedInput">Prepended text</label>
          <div class="controls">
            <div class="input-prepend">
              <span class="add-on">@</span><input class="span2" id="prependedInput" name="prependedInput" size="16" type="text" value="" />
            </div>
            <p class="help-block">Here\'s some help text</p>
          </div>
        </div>
        <div class="control-group">
          <label class="control-label" for="appendedInput">Appended text</label>
          <div class="controls">
            <div class="input-append">
              <input class="span2" id="appendedInput" name="appendedInput" size="16" type="text" value="" /><span class="add-on">.00</span>
            </div>
            <p class="help-block">Here\'s more help text</p>
          </div>
        </div>
        <div class="control-group">
          <label class="control-label" for="inlineCheckboxes">Inline checkboxes</label>
          <div class="controls">
            <label class="checkbox inline" for="inlineCheckboxes.0">
              <input type="checkbox" id="inlineCheckboxes.0" name="inlineCheckboxes" value="option1"> 1
            </label>
            <label class="checkbox inline" for="inlineCheckboxes.1">
              <input type="checkbox" id="inlineCheckboxes.1" name="inlineCheckboxes" value="option2"> 2
            </label>
            <label class="checkbox inline" for="inlineCheckboxes.2">
              <input type="checkbox" id="inlineCheckboxes.2" name="inlineCheckboxes" value="option3"> 3
            </label>
          </div>
        </div>
        <div class="control-group">
          <label class="control-label">Checkboxes</label>
          <div class="controls">
            <label class="checkbox" for="optionsCheckboxList1">
              <input type="checkbox" name="optionsCheckboxList1" id="optionsCheckboxList1" value="option1">
              Option one is this and that&mdash;be sure to include why it’s great
            </label>
            <label class="checkbox" for="optionsCheckboxList2">
              <input type="checkbox" name="optionsCheckboxList2" id="optionsCheckboxList2" value="option2">
              Option two can also be checked and included in form results
            </label>
            <label class="checkbox" for="optionsCheckboxList3">
              <input type="checkbox" name="optionsCheckboxList3" id="optionsCheckboxList3" value="option3">
              Option three can&mdash;yes, you guessed it&mdash;also be checked and included in form results
            </label>
            <p class="help-text"><strong>Note:</strong> Labels surround all the options for much larger click areas and a more usable form.</p>
          </div>
        </div>
        <div class="control-group">
          <label class="control-label" for="optionsRadios">Radio buttons</label>
          <div class="controls">
            <label class="radio" for="optionsRadios.0">
              <input type="radio" name="optionsRadios" id="optionsRadios.0" value="option1" />
              Option one is this and that&mdash;be sure to include why it’s great
            </label>
            <label class="radio" for="optionsRadios.1">
              <input type="radio" name="optionsRadios" id="optionsRadios.1" value="option2" />
              Option two can is something else and selecting it will deselect option one
            </label>
          </div>
        </div>
        <div class="form-actions">
          <button type="submit" class="btn btn-primary">Save changes</button>
          <button type="reset" class="btn">Cancel</button>
        </div>
      </fieldset>
    </form>
  </div>
</div>';

done_testing;