Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add support for disabled attributes to multi-checkbox.

  • Loading branch information...
commit 642db5ee8acf24ee9c806e2f7b2b72fcbadff826 1 parent 770bc7c
Mark Story markstory authored
5 src/View/Input/MultiCheckbox.php
View
@@ -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);
}
77 tests/TestCase/View/Input/MultiCheckboxTest.php
View
@@ -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);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.