Skip to content

Commit

Permalink
Merge pull request #12305 from chinpei215/fix-multi-checkbox
Browse files Browse the repository at this point in the history
MultiCheckboxWidget should use checkboxWrapper, not radioWrapper.
  • Loading branch information
markstory committed Jun 29, 2018
2 parents 9db38a8 + 0dc1d7a commit ed8cc80
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/View/Widget/MultiCheckboxWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ protected function _renderInput($checkbox, $context)
)
]);

if ($checkbox['label'] === false && strpos($this->_templates->get('radioWrapper'), '{{input}}') === false) {
if ($checkbox['label'] === false && strpos($this->_templates->get('checkboxWrapper'), '{{input}}') === false) {
$label = $input;
} else {
$labelAttrs = [
Expand Down
71 changes: 71 additions & 0 deletions tests/TestCase/View/Widget/MultiCheckboxWidgetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,77 @@ public function testRenderTemplateVars()
$this->assertHtml($expected, $result);
}

/**
* Test label = false with checkboxWrapper option.
*
* @return void
*/
public function testNoLabelWithCheckboxWrapperOption()
{
$data = [
'label' => false,
'name' => 'test',
'options' => [
1 => 'A',
2 => 'B',
],
];

$label = new LabelWidget($this->templates);
$input = new MultiCheckboxWidget($this->templates, $label);
$result = $input->render($data, $this->context);
$expected = [
['div' => ['class' => 'checkbox']],
['input' => [
'type' => 'checkbox',
'name' => 'test[]',
'value' => 1,
'id' => 'test-1',
]],
['label' => ['for' => 'test-1']],
'A',
'/label',
'/div',
['div' => ['class' => 'checkbox']],
['input' => [
'type' => 'checkbox',
'name' => 'test[]',
'value' => '2',
'id' => 'test-2',
]],
['label' => ['for' => 'test-2']],
'B',
'/label',
'/div',
];
$this->assertHtml($expected, $result);

$templates = [
'checkboxWrapper' => '<div class="checkbox">{{label}}</div>',
];
$this->templates->add($templates);
$result = $input->render($data, $this->context);
$expected = [
['div' => ['class' => 'checkbox']],
['input' => [
'type' => 'checkbox',
'name' => 'test[]',
'value' => 1,
'id' => 'test-1',
]],
'/div',
['div' => ['class' => 'checkbox']],
['input' => [
'type' => 'checkbox',
'name' => 'test[]',
'value' => '2',
'id' => 'test-2',
]],
'/div',
];
$this->assertHtml($expected, $result);
}

/**
* Test render with groupings.
*
Expand Down

0 comments on commit ed8cc80

Please sign in to comment.