Home » Database » DB_DataObject_FormBuilder » Bug #3167
checkbox type does not permitting setting a DB_DATAOBJECT_BOOL field to false
Details
| Submitted | 2005-01-11 20:09 UTC |
|---|---|
| From | ate2 at cornell dot edu |
| Assigned | justinpatrin |
| Status | Closed |
| Package | DB_DataObject_FormBuilder |
| PHP Version | Irrelevant |
| OS | Irrelevant |
| Roadmaps | (Not assigned) |
Comments
[2005-01-11 20:09 UTC] ate2 at cornell dot edu
Description:
------------
The checkbox value only registers in a form if it is checked. Consequently an unchecked checkbox won't register at all. Thus you can set a boolean from false to true but not true to false with the present automatic type of DB_DATAOBJECT_BOOL fields. Better to use the otherwise identical "advcheckbox" type which uses javascript and hidden fields to add this functionality to the basic checkbox type. This has been working well for me.
One small problem (with either checkbox) would be that it could be possible to have a NULL boolean field in which case there would be a third value to consider. Maybe should generate a select element with empty option for null bool fields?
Reproduce code:
---------------
// Assume user has unchecked the box
$do =& new DataObject();
$do->boolVal = true;
$fb =& new DataObject_FormBuilder($do);
$form =& $fb->getForm();
if ($do->validate()) {
$fb->processForm($form->exportValues());
if ($do->boolVal) {
"Value is true";
}
else {
"Value is false";
}
}
echo $form->toHtml();
Expected result:
----------------
"Value is false"
Actual result:
--------------
"Value is true"