Skip to content

Commit

Permalink
Add support for disabled attributes to multi-checkbox.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jan 15, 2014
1 parent 770bc7c commit 642db5e
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/View/Input/MultiCheckbox.php
Expand Up @@ -128,9 +128,12 @@ protected function _isSelected($key, $selected) {
* @return boolean
*/
protected function _isDisabled($key, $disabled) {
if ($disabled === null) {
if ($disabled === null || $disabled === false) {
return false;
}
if ($disabled === true) {
return true;
}
$strict = !is_numeric($key);
return in_array((string)$key, $disabled, $strict);
}
Expand Down
77 changes: 75 additions & 2 deletions tests/TestCase/View/Input/MultiCheckboxTest.php
Expand Up @@ -107,7 +107,8 @@ public function testRenderSelected() {
1 => 'CakePHP',
'1x' => 'Development',
],
'val' => [1]
'val' => [1],
'disabled' => false
];
$result = $input->render($data);
$expected = [
Expand Down Expand Up @@ -152,7 +153,79 @@ public function testRenderSelected() {
* @return void
*/
public function testRenderDisabled() {
$this->markTestIncomplete();
$input = new MultiCheckbox($this->templates);
$data = [
'name' => 'Tags[id]',
'options' => [
1 => 'CakePHP',
'1x' => 'Development',
],
'disabled' => true,
];
$result = $input->render($data);
$expected = [
['div' => ['class' => 'checkbox']],
['input' => [
'type' => 'checkbox',
'name' => 'Tags[id][]',
'value' => 1,
'id' => 'tags-id-1',
'disabled' => 'disabled'
]],
['label' => ['for' => 'tags-id-1']],
'CakePHP',
'/label',
'/div',
['div' => ['class' => 'checkbox']],
['input' => [
'type' => 'checkbox',
'name' => 'Tags[id][]',
'value' => '1x',
'id' => 'tags-id-1x',
'disabled' => 'disabled'
]],
['label' => ['for' => 'tags-id-1x']],
'Development',
'/label',
'/div',
];
$this->assertTags($result, $expected);

$data = [
'name' => 'Tags[id]',
'options' => [
1 => 'CakePHP',
'1x' => 'Development',
],
'disabled' => [1]
];
$result = $input->render($data);
$expected = [
['div' => ['class' => 'checkbox']],
['input' => [
'type' => 'checkbox',
'name' => 'Tags[id][]',
'value' => 1,
'id' => 'tags-id-1',
'disabled' => 'disabled'
]],
['label' => ['for' => 'tags-id-1']],
'CakePHP',
'/label',
'/div',
['div' => ['class' => 'checkbox']],
['input' => [
'type' => 'checkbox',
'name' => 'Tags[id][]',
'value' => '1x',
'id' => 'tags-id-1x',
]],
['label' => ['for' => 'tags-id-1x']],
'Development',
'/label',
'/div',
];
$this->assertTags($result, $expected);
}

}

0 comments on commit 642db5e

Please sign in to comment.