Details
Description
When an element on a Zend_Dojo_Form_SubForm has a datastore, the generated JS to link the datastore uses the wrong ID.
The id's used to be in the form of subform[element], however this has been changed to subfrom-element, and the generated JavaScript does not reflect this.
Here is a test to replicate the issue:
<?php require_once 'Zend/Controller/Action.php'; require_once 'Zend/Dojo/Form.php'; require_once 'Zend/Dojo/Form/SubForm.php'; require_once 'Zend/Dojo/Form/Element/ComboBox.php'; class TestController extends Zend_Controller_Action { public function dojoTestAction() { // Zend_Dojo_Form $testForm = new Zend_Dojo_Form(); $testForm->setName('testform'); // Create a new subform $testSubform = new Zend_Dojo_Form_SubForm(); // Add a test element to the subform $testSubform->addElement(new Zend_Dojo_Form_Element_ComboBox('testcombo', array( 'storeId' => 'testStore', 'storeType' => 'test.storeType', 'storeParams' => array( 'url' => 'test/store', ), 'label' => 'Test Label:', ) )); // Add the subform to the main form $testForm->addSubForm($testSubform, 'testsubform'); echo $testForm; echo $this->view->dojo(); exit(); } } ?>
Here is the HTML:
<form id="testform"><dl class="zend_form_dojo"> <div name="testsubform" id="testsubform-ContentPane"><dl> <dt id="testcombo-label"><label for="testsubform-testcombo" class="optional">Test Label:</label></dt> <dd> <input options="" listsep="<br />" id="testsubform-testcombo" name="testsubform[testcombo]" value="" type="text"></dd></dl></div> </dl></form> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/dojo/1.2.0/dojo/dojo.xd.js"></script>
And the generated JavaScript:
<script type="text/javascript">
//<!--
dojo.require("test.storeType");
dojo.require("dijit.form.ComboBox");
dojo.require("dijit.layout.ContentPane");
dojo.require("dijit.form.Form");
dojo.require("dojo.parser");
dojo.addOnLoad(function() {
dojo.forEach(zendDijits, function(info) {
var n = dojo.byId(info.id);
if (null != n) {
dojo.attr(n, dojo.mixin({ id: info.id }, info.params));
}
});
dojo.parser.parse();
});
dojo.addOnLoad(function() {
var testStore = new test.storeType({"url":"test\/store"});
dijit.byId("testsubform[testcombo]").attr("store", testStore);
});
var zendDijits = [{"id":"testsubform-testcombo","params":{"dojoType":"pf.form.ComboBox"}},{"id":"testsubform-ContentPane","params":{"title":"","dojoType":"dijit.layout.ContentPane"}},{"id":"testform","params":{"dojoType":"dijit.form.Form"}}];
//-->
</script>
As you can see in the generated javascript.:
dijit.byId("testsubform[testcombo]").attr("store", testStore);
SHOULD BE
dijit.byId("testsubform-testcombo").attr("store", testStore);
OR
The id's should actually be testsubform[testcombo], as it was previously.
The Problem is in
Zend/Dojo/View/Helper/comboBox.php:73
if (false !== ($store = $this->_renderStore($params['store'], $id))) {just replace with this ...
if (false !== ($store = $this->_renderStore($params['store'], $attribs['id']))) {Work fine for me
if (false !== ($store = $this->_renderStore($params['store'], $id))) {if (false !== ($store = $this->_renderStore($params['store'], $attribs['id']))) {