Skip to content

Commit

Permalink
Fixing form helper checkbox hidden input generation for disabled fiel…
Browse files Browse the repository at this point in the history
…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
jperras committed May 14, 2009
1 parent 8c243ee commit 4f2d659
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cake/libs/view/helpers/form.php
Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions cake/tests/cases/libs/view/helpers/form.test.php
Expand Up @@ -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
*
Expand Down

0 comments on commit 4f2d659

Please sign in to comment.