Issues

ZF-5987: Dijit parsing before store creation results in FilteringSelect and ComboBox dijits not working properly.

Issue Type: Bug Created: 2009-03-10T15:20:49.000+0000 Last Updated: 2009-07-21T08:31:51.000+0000 Status: Resolved Fix version(s): Reporter: David Kidd (furiousoyster) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Form

  • Zend_View

Related issues: - ZF-6018

Attachments:

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:

<pre class="highlight">
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:

<pre class="highlight">
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:

<pre class="highlight">
$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'           => '<a href="http://foo.com/userautocomplete">http://foo.com/userautocomplete</a>',
                        'requestMethod' => 'get',
                    ),
            ));
            
$form->addElement( $author_fld );

Comments

Posted by Erik Wahlstrom (ewahlstr) on 2009-03-12T02:45:37.000+0000

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:

$this->dojo()->prependOnLoad('function(){newMentorStore = new dojo.data.ItemFileReadStore();}');

For me, however, the dojo.onLoad() script that this generates is still placed after the ZF parsing function like so:

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();});

Posted by Erik Wahlstrom (ewahlstr) on 2009-03-12T03:05:11.000+0000

I was just able to find a work-around for this issue that might help in brainstorming for a solution...

Instead of assigning the store to the dojo widget using the Zend_Dojo_Form view helper method:

    $mentorSelectionForm->addElement('filteringSelect', 'child_primary_mentor', array(
                                     'label'        => 'Primary Mentor',
                                     'onChange'     => 'mentorSelectionChanged',
                                     'store'        => 'mentorStore',
                                     'searchAttr'   => 'mentor_name'
                                    ));

Create the element without assigning the store and in the dojo()->onLoadCaptureStart() (since we can now grab our widgets using dijit.byId) create the store as usual and then assign it to the widget like so:

    mentorStore = new dojo.data.ItemFileReadStore({
      url: '/blablabla',
      clearOnClose: true
    });
    dijit.byId('child_primary_mentor').attr('store', mentorStore);

Posted by Matthew Weier O'Phinney (matthew) on 2009-03-13T08:37:17.000+0000

Fixed in trunk and 1.7 release branch

Posted by Denis Baklikov (denis.baklikov) on 2009-03-25T22:48:48.000+0000

This issue is not fixed. Can you please check it again?

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:

<pre class="highlight">
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":{"searchAttr":"name","ignoreCase":"true","autocomplete":"true"},"dojoType":"dijit.form.FilteringSelect",{"id":"model","params":{"label":"Models","store":"modelStore","dijitParams":{"searchAttr":"name","ignoreCase":"true","autocomplete":"true"},"dojoType":"dijit.form.FilteringSelect",{"id":"price","params":{"currency":"USD","required":"true","dojoType":"dijit.form.CurrencyTextBox",{"id":"year","params":{"places":0,"constraints":"{\"min\":1970,\"max\":2009,\"pattern\":\"####\"}","required":"true","dojoType":"dijit.form.NumberTextBox",{"id":"mileage","params":{"places":4,"dojoType":"dijit.form.NumberTextBox",{"id":"description","params":{"required":"true","style":"width: 200px;","dojoType":"dijit.form.Textarea",{"id":"save","params":{"label":"\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c","dojoType":"dijit.form.Button"];

Posted by Miguel Angel Perez (mangelp) on 2009-06-12T06:19:43.000+0000

Hello,

I'm having problems with this issue that still exists in ZF 1.8.3, is there any chance of having it really fixed soon?

Posted by Matthew Weier O'Phinney (matthew) on 2009-06-18T11:22:49.000+0000

Please see ZF-6148 -- a solution is now in trunk and the 1.8 release branch, and will release with 1.8.4.

Posted by Raj Mudaliar (iconmans) on 2009-07-21T08:31:51.000+0000

Hi again,

I'm having save problems with ZF 1.8.4. Looks like the code is not yet in 1.8.4

Please update,

Thanks,

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts