Zend Framework

When an dijit on a Zend_Dojo_Form_SubForm has a datastore, the generated JS to link the datastore uses the wrong ID.

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.8.3, 1.8.4, 1.9.0
  • Fix Version/s: 1.9.5
  • Component/s: Zend_Dojo
  • Labels:
    None

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="&lt;br /&gt;" 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.

Activity

Hide
Robert Hänsel added a comment -

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

Show
Robert Hänsel added a comment - 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
Hide
Fabien Faille added a comment -

This bug isn't only for subforms but all elements with stores...

A very simple exemple :

$dojoForm = new Zend_Dojo_Form();
		$dojoForm->addElement("FilteringSelect", "elementName", array(
			'label' => "my label",
			'storeId' => "my_store_id",
			'storeType' => "dojox.data.QueryReadStore",
			'storeParams' => array(
				'url' => "/some/path"
			),
			'attribs' => array(
				'id' => "my_element_id"
			)
		));

rendered code

var my_store_id = new dojox.data.QueryReadStore({"url":"\/some\/path"});
dijit.byId("elementName").attr("store", my_store_id);

Fix given by Robert Hänsel (18/Aug/09 12:52 AM) works well, it's possible you have to make the same change on line 96...

Show
Fabien Faille added a comment - This bug isn't only for subforms but all elements with stores... A very simple exemple :
$dojoForm = new Zend_Dojo_Form();
		$dojoForm->addElement("FilteringSelect", "elementName", array(
			'label' => "my label",
			'storeId' => "my_store_id",
			'storeType' => "dojox.data.QueryReadStore",
			'storeParams' => array(
				'url' => "/some/path"
			),
			'attribs' => array(
				'id' => "my_element_id"
			)
		));
rendered code
var my_store_id = new dojox.data.QueryReadStore({"url":"\/some\/path"});
dijit.byId("elementName").attr("store", my_store_id);
Fix given by Robert Hänsel (18/Aug/09 12:52 AM) works well, it's possible you have to make the same change on line 96...
Hide
Marcin Sikon added a comment -

The bug is in file Zend/Dojo/View/Helper/ComboBox.php

 
148                    . 'dijit.byId("' . $id . '").attr("store", '
{/noformat} 

should be

148 . 'dijit.byId("' . $this->_normalizeId($id). '").attr("store", '

{/noformat}
Show
Marcin Sikon added a comment - The bug is in file Zend/Dojo/View/Helper/ComboBox.php
 
148                    . 'dijit.byId("' . $id . '").attr("store", '
{/noformat} 

should be
148 . 'dijit.byId("' . $this->_normalizeId($id). '").attr("store", ' {/noformat}
Hide
Matthew Weier O'Phinney added a comment -

Fixed in trunk and 1.9 release branch.

Show
Matthew Weier O'Phinney added a comment - Fixed in trunk and 1.9 release branch.

People

Vote (8)
Watch (10)

Dates

  • Created:
    Updated:
    Resolved: