Details
Description
If a ComboBox or FilteringSelect element is parsed before its store has been instantiated, it won't use the store. In previous versions of ZF, the ordering of dojo.addOnLoad functions put store creation before dijit parsing. In 1.7.6, dijits are parsed first (I believe this is because of ZF-4587). This means forms using ComboBoxes and FilteringSelects which used to work in 1.7.5 no longer work correctly.
The following code, produced by 1.7.6 does not work:
dojo.require("custom.AutocompleteReadStore"); dojo.require("dijit.form.FilteringSelect"); 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() { autocompleter = new custom.AutocompleteReadStore({"url":"http:\/\/foo.com\/userautocomplete","requestMethod":"get"}); }); var autocompleter; var zendDijits = [{"id":"author_id","params":{"store":"autocompleter","dojoType":"dijit.form.FilteringSelect"}},{"id":"the_form","params":{"dojoType":"dijit.form.Form"}}];
The following, created by 1.7.5, however, does work:
dojo.require("custom.AutocompleteReadStore"); dojo.require("dijit.form.FilteringSelect"); dojo.require("dijit.form.Form"); dojo.require("dojo.parser"); dojo.addOnLoad(function() { autocompleter = new custom.AutocompleteReadStore({"url":"http:\/\/foo.com\/userautocomplete","requestMethod":"get"}); }); 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 autocompleter; var zendDijits = [{"id":"author_id","params":{"store":"autocompleter","dojoType":"dijit.form.FilteringSelect"}},{"id":"the_form","params":{"dojoType":"dijit.form.Form"}}];
Both examples result from the following addition to a Zend_Dojo_Form:
$author_fld = new Zend_Dojo_Form_Element_FilteringSelect( 'author_id', array( 'label' => 'Author:', // The javascript identifier for the data store: 'storeId' => 'autocompleter', // The class type for the data store: 'storeType' => 'custom.AutocompleteReadStore', // Parameters to use when initializing the data store: 'storeParams' => array( 'url' => 'http://foo.com/userautocomplete', 'requestMethod' => 'get', ), )); $form->addElement( $author_fld );
Issue Links
| This issue is duplicated by: | ||||
| ZF-6018 | Zend_Dojo_Form_Element_ComboBox doesn't works with zend_dojo_dataStore |
|
|
|
I am experiencing the same side-effects from the new changes in 1.7.6. Funny because I remember wanting the onLoadCaptureStart to function in this manner so we could utilize dojo.connect statements on parsed widgets - didn't foresee this problem though...
It appears as if the prependOnLoad() method of the Dojo view helper would solve this problem - simply create the data store like so:
<code>
$this->dojo()->prependOnLoad('function(){newMentorStore = new dojo.data.ItemFileReadStore();}');
</code>
For me, however, the dojo.onLoad() script that this generates is still placed after the ZF parsing function like so:
<code>
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(){newMentorStore = new dojo.data.ItemFileReadStore();});
</code>