Skip to content
Permalink
Browse files

Add support for disabled attributes to multi-checkbox.

  • Loading branch information...
markstory committed Jan 15, 2014
1 parent 770bc7c commit 642db5ee8acf24ee9c806e2f7b2b72fcbadff826
Showing with 79 additions and 3 deletions.
  1. +4 −1 src/View/Input/MultiCheckbox.php
  2. +75 −2 tests/TestCase/View/Input/MultiCheckboxTest.php
@@ -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);
}
@@ -107,7 +107,8 @@ public function testRenderSelected() {
1 => 'CakePHP',
'1x' => 'Development',
],
'val' => [1]
'val' => [1],
'disabled' => false
];
$result = $input->render($data);
$expected = [
@@ -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.
You can’t perform that action at this time.