Select to view content in your preferred language

Bug with dojo/on is version 3.7

3340
24
Jump to solution
10-02-2013 07:06 AM
ShawnHolyoak
Deactivated User
In upgrading my application to version 3.7 of the api, I've run into what I believe is a bug.  When I try to connect to the layers-add-result event for my map, I try to use the dojo/on amd method.  My code for that is:
on(map, "layers-add-result", function(e) {   var toc = new agsjs.dijit.TOC({    map: map,    layerInfos:legendLayers   }, 'legendDiv');   toc.startup();  });


That returns an error "TypeError: Cannot read property 'tagName' of undefined ".  When I try using the old dojo.connect method, though, everything works.  My code using the old dojo.connect is:
dojo.connect(map,'onLayersAddResult', function(results){   var toc = new agsjs.dijit.TOC({    map: map,    layerInfos:legendLayers   }, 'legendDiv');   toc.startup();  });


According to the documents, version 3.7 is using dojo version 1.9.1, which should certainly support the dojo/on functionality.  What, if anything, am I doing wrong.  If I'm not doing anything wrong, how do I file a bug report?
0 Kudos
24 Replies
JohnGravois
Deactivated User
i guess now i disagree with you on two counts. 🙂  i did a quick check modifying this sample and had no trouble wiring up the navigation toolbar's sole on style event handler.

navToolbar.on("extent-history-change", extentHistoryChangeHandler);
...
function extentHistoryChangeHandler() {
        console.log("fired");
 dijit.byId("zoomprev").disabled = navToolbar.isFirstExtent();
        dijit.byId("zoomnext").disabled = navToolbar.isLastExtent();
}


with regard to Dojo 'allowing' on style events in 1.9x.  using a Dojo method would only be necessary for a DOM node that didn't already have a listener defined. 

since the map class is already 'evented', you should simply use the method thats already present.

consider that a strong opinion, weakly held 🙂
0 Kudos
ShawnHolyoak
Deactivated User
i guess now i disagree with you on two counts. 🙂  i did a quick check modifying this sample and had no trouble wiring up the navigation toolbar's sole on style event handler.

navToolbar.on("extent-history-change", extentHistoryChangeHandler);
...
function extentHistoryChangeHandler() {
        console.log("fired");
 dijit.byId("zoomprev").disabled = navToolbar.isFirstExtent();
        dijit.byId("zoomnext").disabled = navToolbar.isLastExtent();
}


with regard to Dojo 'allowing' on style events in 1.9x.  using a Dojo method would only be necessary for a DOM node that didn't already have a listener defined. 

since the map class is already 'evented', you should simply use the method thats already present.

consider that a strong opinion, weakly held 🙂


It may simply be I don't understand either dojo or the jsapi well enough yet, because I received a "object nav has no method on" error when I tried that, whereas with the
on(nav, 'extent-history-change', _this.extentHistoryChanged);

approach, it worked which of course is the opposite of what led me to post this question originally.  Basically, in certain situations one works while the other doesn't, and in other situations it's the reverse, probably related to the asynchronous nature of the api.  Pretty frustrating for those of us that are simply trying to keep up...
0 Kudos
JohnGravois
Deactivated User
feel free to post a simple sample.  i'd be happy to take a look.
0 Kudos
ShawnHolyoak
Deactivated User
feel free to post a simple sample.  i'd be happy to take a look.


I appreciate that, but as we discovered earlier (see the thread above), I had no problems with the api in jsfiddle.  The simple samples are easy.  It's when trying to put everything together in a large application that it gets difficult.
0 Kudos
AleydisG__Pere
Regular Contributor
Checking the differences in the documentation. Both work.

on(navToolbar, "ExtentHistoryChange", extentHistoryChangeHandler);

navToolbar.on("extent-history-change", extentHistoryChangeHandler);


The same goes for on(map,...)/map.on(...):

on(map, "LayersAddResult", function(e));

map.on("layers-add-result", function(e));
0 Kudos