Skip to content
This repository
Browse code

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
Joel Perras authored May 14, 2009
2  cake/libs/view/helpers/form.php
@@ -853,7 +853,7 @@ function checkbox($fieldName, $options = array()) {
853 853
 			'id' => $options['id'] . '_', 'name' => $options['name'],
854 854
 			'value' => '0', 'secure' => false
855 855
 		);
856  
-		if (isset($options['disabled'])) {
  856
+		if (isset($options['disabled']) && $options['disabled'] == true) {
857 857
 			$hiddenOptions['disabled'] = 'disabled';
858 858
 		}
859 859
 		$output = $this->hidden($fieldName, $hiddenOptions);
15  cake/tests/cases/libs/view/helpers/form.test.php
@@ -3165,6 +3165,21 @@ function testCheckboxDisabling() {
3165 3165
 		);
3166 3166
 		$this->assertTags($result, $expected);
3167 3167
 	}
  3168
+	
  3169
+/**
  3170
+ * Test that specifying false in the 'disabled' option will not disable either the hidden input or the checkbox input
  3171
+ *
  3172
+ * @return void
  3173
+ **/
  3174
+	function testCheckboxHiddenDisabling() {
  3175
+		$result = $this->Form->checkbox('Account.show_name', array('disabled' => false));
  3176
+		$expected = array(
  3177
+			array('input' => array('type' => 'hidden', 'name' => 'data[Account][show_name]', 'value' => '0', 'id' => 'AccountShowName_')),
  3178
+			array('input' => array('type' => 'checkbox', 'name' => 'data[Account][show_name]', 'value' => '1', 'id' => 'AccountShowName'))
  3179
+		);
  3180
+		$this->assertTags($result, $expected);
  3181
+	}
  3182
+	
3168 3183
 /**
3169 3184
  * testDateTime method
3170 3185
  *

0 notes on commit 4f2d659

Please sign in to comment.
Something went wrong with that request. Please try again.