Adding fix for Ticket #2795, fixes hidden field for checkbox.

Updated FormHelperTest::testCheckboxField() to reflect the correct return value

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5310 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-06-20 04:30:45 +00:00
parent b9f56fb0a7
commit d93d746663
2 changed files with 10 additions and 7 deletions

View file

@ -655,8 +655,8 @@ class FormHelper extends AppHelper {
$db =& ConnectionManager::getDataSource($object->useDbConfig);
$value = $db->boolean($options['value']);
$options['value'] = 1;
$output = $this->hidden($fieldName, array('value' => '0', 'id' => $options['id'] . '_'), true);
}
$output = $this->hidden($fieldName, array('value' => '0', 'id' => $options['id'] . '_'), true);
if(isset($options['value']) && $value == $options['value']) {
$options['checked'] = 'checked';

View file

@ -821,19 +821,22 @@ class FormHelperTest extends CakeTestCase {
$this->Form->validationErrors['Model']['field'] = 1;
$this->Form->data['Model']['field'] = 'myvalue';
$result = $this->Form->checkbox('Model.field', array('id'=>'theID', 'value' => 'myvalue'));
$this->assertEqual($result, '<input type="checkbox" name="data[Model][field]" type="checkbox" id="theID" value="myvalue" class="form-error" checked="checked" />');
$this->assertEqual($result, '<input type="hidden" name="data[Model][field]" value="0" id="theID_" class="form-error" /><input type="checkbox" name="data[Model][field]" type="checkbox" id="theID" value="myvalue" class="form-error" checked="checked" />');
$this->Form->data['Model']['field'] = '';
$result = $this->Form->checkbox('Model.field', array('id'=>'theID', 'value' => 'myvalue'));
$this->assertEqual($result, '<input type="checkbox" name="data[Model][field]" type="checkbox" id="theID" value="myvalue" class="form-error" />');
$this->assertEqual($result, '<input type="hidden" name="data[Model][field]" value="0" id="theID_" class="form-error" /><input type="checkbox" name="data[Model][field]" type="checkbox" id="theID" value="myvalue" class="form-error" />');
$this->Form->validationErrors['Model']['field'] = 0;
$result = $this->Form->checkbox('Model.field', array('value' => 'myvalue'));
$this->assertEqual($result, '<input type="checkbox" name="data[Model][field]" type="checkbox" value="myvalue" id="ModelField" />');
$this->assertEqual($result, '<input type="hidden" name="data[Model][field]" value="0" id="ModelField_" /><input type="checkbox" name="data[Model][field]" type="checkbox" value="myvalue" id="ModelField" />');
$result = $this->Form->checkbox('Contact.field', array('value' => 'myvalue'));
$this->assertEqual($result, '<input type="checkbox" name="data[Contact][field]" type="checkbox" value="myvalue" id="ContactField" />');
$this->assertEqual($result, '<input type="hidden" name="data[Contact][field]" value="0" id="ContactField_" /><input type="checkbox" name="data[Contact][field]" type="checkbox" value="myvalue" id="ContactField" />');
$result = $this->Form->checkbox('Model.field');
$this->assertEqual($result, '<input type="hidden" name="data[Model][field]" value="0" id="ModelField_" /><input type="checkbox" name="data[Model][field]" type="checkbox" value="1" id="ModelField" />');
$this->Form->validationErrors['Model']['field'] = 1;
$this->Form->data['Contact']['published'] = 1;
$result = $this->Form->checkbox('Contact.published', array('id'=>'theID'));
@ -851,4 +854,4 @@ class FormHelperTest extends CakeTestCase {
}
}
?>
?>