Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixing form helper checkbox hidden input generation for disabled fiel…

…ds. 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
  • Loading branch information...
commit 4f2d65943f860f23f77f3f834bdebb5506eaa45a 1 parent 8c243ee
@jperras jperras authored
View
2  cake/libs/view/helpers/form.php
@@ -853,7 +853,7 @@ function checkbox($fieldName, $options = array()) {
'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);
View
15 cake/tests/cases/libs/view/helpers/form.test.php
@@ -3165,6 +3165,21 @@ function testCheckboxDisabling() {
);
$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
*
Please sign in to comment.
Something went wrong with that request. Please try again.