Details
-
Type:
Patch
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.7.0
-
Fix Version/s: None
-
Component/s: Zend_Dojo
-
Labels:None
Description
Zend_Dojo_Form checkbox generates incorrect HTML. Assuming a working Zend_Dojo environment, the following code produces the error:
"TestController.php"
class TestController extends Zend_Controller_Action { function indexAction () { $this->view->addHelperPath('Zend/Dojo/View/Helper/', 'Zend_Dojo_View_Helper'); $form = new Zend_Dojo_Form(); $form->addElement( 'CheckBox', 'checkboxValue', array( 'label' => 'Label', 'checkedValue' => 'checkedValue', 'uncheckedValue' => 'notCheckedValue', ) ); $form->addDecorators(array('FormElements', 'Form')); $this->view->form = $form; } }
This produces the following HTML:
<input name="checkboxValue" value="0" type="hidden"><input id="checkboxValue" name="checkboxValue" value="notCheckedValue" type="checkbox">
The correct HTML should be:
<input name="checkboxValue" value="notCheckedValue" type="hidden"><input id="checkboxValue" name="checkboxValue" value="checkedValue" type="checkbox">
Tested against SVN Trunk r 11380.
This is the wrong fix, but it is a fix. The problem is that the $checkedOptions parameter is not set when passed to the Helper.
--- Zend/Dojo/View/Helper/CheckBox.php (revision 11380) +++ Zend/Dojo/View/Helper/CheckBox.php (working copy) /** Zend_Dojo_View_Helper_Dijit */ @@ -72,7 +72,11 @@ } elseif (isset($attribs['checked'])) { $checked = false; } + + $checkedOptions = $attribs['options']; + $checkboxInfo = Zend_View_Helper_FormCheckbox::determineCheckboxInfo($value, $checked, $checkedOptions); $attribs['checked'] = $checkboxInfo['checked']; if (!array_key_exists('id', $attribs)) { $attribs['id'] = $id;--- Zend/Dojo/View/Helper/CheckBox.php (revision 11380) +++ Zend/Dojo/View/Helper/CheckBox.php (working copy) /** Zend_Dojo_View_Helper_Dijit */ @@ -72,7 +72,11 @@ } elseif (isset($attribs['checked'])) { $checked = false; } + + $checkedOptions = $attribs['options']; + $checkboxInfo = Zend_View_Helper_FormCheckbox::determineCheckboxInfo($value, $checked, $checkedOptions); $attribs['checked'] = $checkboxInfo['checked']; if (!array_key_exists('id', $attribs)) { $attribs['id'] = $id;