Skip to content

Commit

Permalink
Fix issue with label=false.
Browse files Browse the repository at this point in the history
Only return the input for checkbox type inputs as they are normally
nested in the label.

Fixes #4991
  • Loading branch information
markstory committed Oct 28, 2014
1 parent f78a238 commit 4c91a0f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/View/Helper/FormHelper.php
Expand Up @@ -1179,7 +1179,7 @@ protected function _getLabel($fieldName, $options) {
$label = $options['label'];
}

if ($label === false && isset($options['input'])) {
if ($label === false && $options['type'] === 'checkbox') {
return $options['input'];
}
if ($label === false) {
Expand Down
25 changes: 25 additions & 0 deletions tests/TestCase/View/Helper/FormHelperTest.php
Expand Up @@ -5169,6 +5169,22 @@ public function testInputDate() {
$this->assertNotContains('value="2008" selected="selected"', $result);
}

/**
* Test the label option being set to false.
*
* @return void
*/
public function testInputLabelFalse() {
$this->Form->create($this->article);
$result = $this->Form->input('title', ['label' => false]);
$expected = [
'div' => ['class' => 'input text required'],
'input' => ['type' => 'text', 'required' => 'required', 'id' => 'title', 'name' => 'title'],
'/div'
];
$this->assertHtml($expected, $result);
}

/**
* testInputDateMaxYear method
*
Expand Down Expand Up @@ -6231,6 +6247,15 @@ public function testInputsNotNested() {
];
$this->assertHtml($expected, $result);

$result = $this->Form->input('foo', ['type' => 'checkbox', 'label' => false]);
$expected = [
'div' => ['class' => 'input checkbox'],
['input' => ['type' => 'hidden', 'name' => 'foo', 'value' => '0']],
['input' => ['type' => 'checkbox', 'name' => 'foo', 'id' => 'foo', 'value' => '1']],
'/div'
];
$this->assertHtml($expected, $result);

$result = $this->Form->input('confirm', [
'type' => 'radio',
'options' => ['Y' => 'Yes', 'N' => 'No']
Expand Down

0 comments on commit 4c91a0f

Please sign in to comment.