From 4f2d65943f860f23f77f3f834bdebb5506eaa45a Mon Sep 17 00:00:00 2001 From: jperras Date: Thu, 14 May 2009 03:26:53 +0000 Subject: [PATCH] Fixing form helper checkbox hidden input generation for disabled fields. Thanks to 'trevorsg' for the patch & test case. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8173 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/view/helpers/form.php | 2 +- cake/tests/cases/libs/view/helpers/form.test.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 5cff4816d..3fea2a52f 100644 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -853,7 +853,7 @@ class FormHelper extends AppHelper { 'id' => $options['id'] . '_', 'name' => $options['name'], 'value' => '0', 'secure' => false ); - if (isset($options['disabled'])) { + if (isset($options['disabled']) && $options['disabled'] == true) { $hiddenOptions['disabled'] = 'disabled'; } $output = $this->hidden($fieldName, $hiddenOptions); diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 9358df259..2740b0082 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -3165,6 +3165,21 @@ class FormHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); } + +/** + * Test that specifying false in the 'disabled' option will not disable either the hidden input or the checkbox input + * + * @return void + **/ + function testCheckboxHiddenDisabling() { + $result = $this->Form->checkbox('Account.show_name', array('disabled' => false)); + $expected = array( + array('input' => array('type' => 'hidden', 'name' => 'data[Account][show_name]', 'value' => '0', 'id' => 'AccountShowName_')), + array('input' => array('type' => 'checkbox', 'name' => 'data[Account][show_name]', 'value' => '1', 'id' => 'AccountShowName')) + ); + $this->assertTags($result, $expected); + } + /** * testDateTime method *