ZF-6148: Dijit parsing before store creation results in FilteringSelect and ComboBox.

Description

This issue duplicates #5987.

I have got JavaScript error: 'dojo.data is undefined' after migrating to ZF 1.7.7. It seems that JavaScript tried to create new instance of dojo.data.ItemFileReadStore, but it is not loaded yet.

ItemFileReadStore instance should be created after page load, using dojo.addOnLoad method. I think that using prependOnLoad (look at the first comment) instead of addJavascript (in ComboBox.php line 142).

The following code was generated by Dojo View helper:


dojo.require("dojo.data.ItemFileReadStore");
dojo.require("dijit.form.FilteringSelect");
dojo.require("dijit.form.CurrencyTextBox");
dojo.require("dijit.form.NumberTextBox");
dojo.require("dijit.form.Textarea");
dojo.require("dijit.form.Button");
dojo.require("dijit.Dialog");
dojo.require("dijit.ColorPalette");
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();
});

var manufacturerStore = new dojo.data.ItemFileReadStore({"url":"\/manufacturer\/list"});
var modelStore = new dojo.data.ItemFileReadStore({"url":"\/model\/list"});
var zendDijits = [{"id":"manufacturer","params":{"label":"Manufacturer","store":"manufacturerStore","dijitParams",........}}];

Comments

Hello,

Just to say that i have exactly the same problem. With this code :

$nom = new Zend_Dojo_Form_Element_FilteringSelect('nom'); $nom->setLabel('Nom : '); $nom->setAutoComplete(true); $nom->setStoreId('nom'); $nom->setStoreType('dojo.data.ItemFileReadStore'); $nom->setStoreParams(array('url' => '/js/nom.js')); $nom->setAttrib(array('searchAttr' => 'nom')); $nom->setRequired(true); $form->addElement($nom);

i get the same Javascript error :

dojo.data is undefined

and, of course, an empty select field.

Tested with ZF 1.7.8.

Regards, Stephane.

Hello,

ZF 1.8.3 is still affected by this issue despite of #5987 being closed.

Finally have it working correctly. prependOnLoad() does not work, as that method is used by the dojo view helper inernally just prior to rendering to create the dijits -- which means that the dijit creation happens prior to store creation. I did figure it out, however, based on a comment on ZF-5987 by Erik Wahlstrom, and now have an onLoad event that creates the store and assigns it to the dijit's store attribute. I've tested this locally and the solution is solid.

The changes have been patched to trunk and the 1.8 release branch, and will go out with 1.8.4.

this ZF 1.8.4 fix seems to break the following setup, known to work in ZF 1.8.3: 1/ store is statically defined in a view :

2/ filteringselect only sets up store property to targe the statically defined store : $element->setDijitParams( array( 'store' => 'myStore' ) );

With this setup and ZF 1.8.4, FilteringSelect appears empty while myStore is populated

Why am I doing things like this ? Because this is the only way I found to have a filteringselect combo working when loaded into a dojox.dialog (=dojo.dialog + executescript) with a xhrget request.

Jean-fabrice

I have the same problem than Jean-Fabrice. All my filtering select are empty. I have some "linked" filteringselect, when I make change on the first list, the second is affected. Now this dont work at all...

And I've a lot of filtering select in my webapp, what must I do ????

I don't know where else to put this comment, It probably is a new bug, or there might be a better work around.

In 1.8.4, doing something like this in a view:

echo $this->filteringSelect( 'select', '20', array( 'store' => 'store', 'storeType' => 'dojo.data.ItemFileReadStore', 'storeParams' => array('url' => '/my/data')) );

Fails, the 'value' is not set because the store is not loaded when it it parses the input. With a filteringSelect the input remains a textbox with the value set, but it is not a dojo object, and everything else on the page breaks. With a comboBox the value and label are set to the identifier value that I am passing instead of the label getting set properly (assuming because combo box allows things not in the store). I tried putting a 'value' option in the params array, but that doesn't seem to propagate, and even if I test this by hand it still doesn't load properly because of the way things are getting parsed.

Anyone have any idea's? Besides creating all this stuff by hand?