Skip to content

Commit efc3959

Browse files
committed
add checkboxDiv option and modified sample, test case
1 parent 0e2d3e3 commit efc3959

4 files changed

Lines changed: 162 additions & 98 deletions

File tree

Test/Case/View/Helper/BoostCakeFormHelperTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,43 @@ public function testBeforeInputAfterInput() {
128128

129129
public function testCheckbox() {
130130
$result = $this->Form->input('name', array('type' => 'checkbox'));
131+
$this->assertTags($result, array(
132+
array('div' => array()),
133+
array('div' => array('class' => 'input checkbox')),
134+
array('div' => array('class' => 'checkbox')),
135+
array('input' => array('type' => 'hidden', 'name' => 'data[name]', 'id' => 'name_', 'value' => '0')),
136+
'label' => array('for' => 'name'),
137+
array('input' => array('name' => 'data[name]', 'type' => 'checkbox', 'value' => '1', 'id' => 'name')),
138+
' Name',
139+
'/label',
140+
'/div',
141+
'/div',
142+
'/div'
143+
));
144+
145+
$result = $this->Form->input('name', array(
146+
'type' => 'checkbox',
147+
'before' => '<label>Name</label>',
148+
'label' => false
149+
));
150+
$this->assertTags($result, array(
151+
array('div' => array()),
152+
array('label' => array()),
153+
'Name',
154+
'/label',
155+
array('div' => array('class' => 'input checkbox')),
156+
array('div' => array('class' => 'checkbox')),
157+
array('input' => array('type' => 'hidden', 'name' => 'data[name]', 'id' => 'name_', 'value' => '0')),
158+
array('input' => array('name' => 'data[name]', 'type' => 'checkbox', 'value' => '1', 'id' => 'name')),
159+
'/div',
160+
'/div',
161+
'/div'
162+
));
163+
164+
$result = $this->Form->input('name', array(
165+
'type' => 'checkbox',
166+
'checkboxDiv' => false
167+
));
131168
$this->assertTags($result, array(
132169
array('div' => array()),
133170
array('div' => array('class' => 'input checkbox')),

View/BoostCake/bootstrap2.ctp

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@
3535
'after' => '<span class="help-block">Example block-level help text here.</span>'
3636
)); ?>
3737
<?php echo $this->Form->input('checkbox', array(
38-
'label' => array(
39-
'text' => 'Check me out',
40-
'class' => 'checkbox'
41-
)
38+
'label' => 'Check me out'
4239
)); ?>
4340
<?php echo $this->Form->submit('Submit', array(
4441
'div' => false,
@@ -63,10 +60,7 @@ echo h("<?php echo \$this->Form->create('BoostCake', array(
6360
'after' => '<span class=\"help-block\">Example block-level help text here.</span>'
6461
)); ?>
6562
<?php echo \$this->Form->input('checkbox', array(
66-
'label' => array(
67-
'text' => 'Check me out',
68-
'class' => 'checkbox'
69-
)
63+
'label' => 'Check me out'
7064
)); ?>
7165
<?php echo \$this->Form->submit('Submit', array(
7266
'div' => false,
@@ -140,7 +134,8 @@ echo h("<?php echo \$this->Form->create('BoostCake', array(
140134
'label' => array(
141135
'text' => 'Remember me',
142136
'class' => 'checkbox'
143-
)
137+
),
138+
'checkboxDiv' => false
144139
)); ?>
145140
<?php echo $this->Form->submit('Sign in', array(
146141
'div' => false,
@@ -169,7 +164,8 @@ echo h("<?php echo \$this->Form->create('BoostCake', array(
169164
'label' => array(
170165
'text' => 'Remember me',
171166
'class' => 'checkbox'
172-
)
167+
),
168+
'checkboxDiv' => false
173169
)); ?>
174170
<?php echo \$this->Form->submit('Sign in', array(
175171
'div' => false,
@@ -208,10 +204,7 @@ echo h("<?php echo \$this->Form->create('BoostCake', array(
208204
'placeholder' => 'Password'
209205
)); ?>
210206
<?php echo $this->Form->input('remember', array(
211-
'label' => array(
212-
'text' => 'Remember me',
213-
'class' => 'checkbox'
214-
),
207+
'label' => 'Remember me',
215208
'afterInput' => $this->Form->submit('Sign in', array(
216209
'class' => 'btn'
217210
))
@@ -236,10 +229,7 @@ echo h("<?php echo \$this->Form->create('BoostCake', array(
236229
'placeholder' => 'Password'
237230
)); ?>
238231
<?php echo \$this->Form->input('remember', array(
239-
'label' => array(
240-
'text' => 'Remember me',
241-
'class' => 'checkbox'
242-
),
232+
'label' => 'Remember me',
243233
'afterInput' => \$this->Form->submit('Sign in', array(
244234
'class' => 'btn'
245235
))
@@ -296,18 +286,15 @@ echo h("<?php echo \$this->Form->create('BoostCake', array(
296286
)
297287
)
298288
)); ?>
299-
<div class="control-group<?php if ($this->Form->isFieldError('radio')): ?> error<?php endif ?>">
300-
<label class="control-label">Radio</label>
301-
<?php echo $this->Form->input('radio', array(
302-
'type' => 'radio',
303-
'div' => false,
304-
'legend' => false,
305-
'options' => array(
306-
1 => 'Option one is this and that—be sure to include why it\'s great',
307-
2 => 'Option two can be something else and selecting it will deselect option one'
308-
)
309-
)); ?>
310-
</div>
289+
<?php echo $this->Form->input('radio', array(
290+
'type' => 'radio',
291+
'before' => '<label class="control-label">Radio</label>',
292+
'legend' => false,
293+
'options' => array(
294+
1 => 'Option one is this and that—be sure to include why it\'s great',
295+
2 => 'Option two can be something else and selecting it will deselect option one'
296+
)
297+
)); ?>
311298
<?php echo $this->Form->input('username', array(
312299
'placeholder' => 'Username',
313300
'div' => 'control-group input-prepend',
@@ -338,6 +325,17 @@ echo h("<?php echo \$this->Form->create('BoostCake', array(
338325
'placeholder' => 'Password',
339326
'errorMessage' => false
340327
)); ?>
328+
<?php echo $this->Form->input('checkbox', array(
329+
'label' => array('class' => null),
330+
'afterInput' => '<span class="help-block">Checkbox Bootstrap Style</span>'
331+
)); ?>
332+
<?php echo $this->Form->input('checkbox', array(
333+
'div' => false,
334+
'label' => false,
335+
'before' => '<label class="control-label">Checkbox</label>',
336+
'wrapInput' => 'controls',
337+
'afterInput' => '<span class="help-block">Checkbox CakePHP Style</span>'
338+
)); ?>
341339
<div class="form-actions">
342340
<?php echo $this->Form->submit('Save changes', array(
343341
'div' => false,
@@ -391,18 +389,15 @@ echo h("<?php echo \$this->Form->create('BoostCake', array(
391389
)
392390
)
393391
)); ?>
394-
<div class=\"control-group<?php if (\$this->Form->isFieldError('radio')): ?> error<?php endif ?>\">
395-
<label class=\"control-label\">Radio</label>
396-
<?php echo \$this->Form->input('radio', array(
397-
'type' => 'radio',
398-
'div' => false,
399-
'legend' => false,
400-
'options' => array(
401-
1 => 'Option one is this and that—be sure to include why it\'s great',
402-
2 => 'Option two can be something else and selecting it will deselect option one'
403-
)
404-
)); ?>
405-
</div>
392+
<?php echo \$this->Form->input('radio', array(
393+
'type' => 'radio',
394+
'before' => '<label class=\"control-label\">Radio</label>',
395+
'legend' => false,
396+
'options' => array(
397+
1 => 'Option one is this and that—be sure to include why it\'s great',
398+
2 => 'Option two can be something else and selecting it will deselect option one'
399+
)
400+
)); ?>
406401
<?php echo \$this->Form->input('username', array(
407402
'placeholder' => 'Username',
408403
'div' => 'control-group input-prepend',
@@ -433,6 +428,17 @@ echo h("<?php echo \$this->Form->create('BoostCake', array(
433428
'placeholder' => 'Password',
434429
'errorMessage' => false
435430
)); ?>
431+
<?php echo \$this->Form->input('checkbox', array(
432+
'label' => array('class' => null),
433+
'afterInput' => '<span class=\"help-block\">Checkbox Bootstrap Style</span>'
434+
)); ?>
435+
<?php echo \$this->Form->input('checkbox', array(
436+
'div' => false,
437+
'label' => false,
438+
'before' => '<label class=\"control-label\">Checkbox</label>',
439+
'wrapInput' => 'controls',
440+
'afterInput' => '<span class=\"help-block\">Checkbox CakePHP Style</span>'
441+
)); ?>
436442
<div class=\"form-actions\">
437443
<?php echo \$this->Form->submit('Save changes', array(
438444
'div' => false,

0 commit comments

Comments
 (0)