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

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:


Test Label:

And the generated JavaScript:


As you can see in the generated javascript.:


SHOULD BE

OR The id's should actually be testsubform[testcombo], as it was previously.

Comments

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

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...

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}

Fixed in trunk and 1.9 release branch.