Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#13343 closed defect (wontfix)

Using multiple dojo versions breaks getDescendants() in dijit._WidgetBase

Reported by: kentonr Owned by: bill
Priority: high Milestone: tbd
Component: Dijit Version: 1.6.1
Keywords: Cc:
Blocked By: Blocking:

Description (last modified by bill)

Similar to #11910, I have run into an issue where one instance of dojo tries to find widgets from a different instance of dojo. This results in the returned array containing several elements which are undefined, which causes issues in code that assumes all of the elements are defined. An example is in dijit.dialog, or dijit.form which attempt to find all of its descendants for form verification / management purposes.

Since I am using two instances of dojo (though they are the same version), I wrote a workaround:

dijit._WidgetBase.prototype.getDescendants = function() {
	return this.containerNode ? dojo.query('[widgetId]', this.containerNode).map( function(node) {
		var dijitNode = dijit.byNode(node);
		if (dijitNode)
			return dijitNode;
			return esriDijit.byNode(node);
	}) : []; // dijit._Widget[]

Where esriDijit is the remapped dijit namespace for the other dojo instance.

Change History (5)

comment:1 Changed 11 years ago by Douglas Hays

Component: GeneralDijit
Owner: set to bill

comment:2 Changed 11 years ago by bill

Description: modified (diff)
Resolution: wontfix
Status: newclosed

You really should be using getChildren() rather than getDescendants(), but still I could make a change to getDescendants() like in [23319]. Note though that would just make getDescendants() filter out the widgets from another dojo instance, not resolve them like your workaround does.

The thing is though that getDescendants() is deprecated, so I'm reluctant to change it. I'm going to close this as wontfix for now with the suggestion to use getChildren() instead of getDescendants(). (getChildren() is available for all widgets starting in 1.6, or maybe 1.5). If there's some reason you can't use getChildren() let me know; if enough people need getDescendants() I'll un-deprecate it.

comment:3 Changed 11 years ago by kentonr

Thanks for the heads up on getChildren(). However, I ran into this issue because I was embedding a custom widget from a different distribution of Dojo (Esri's) inside a dijit.Dialog, which calls getDescendants in several areas (as it inherits from dijit._FormMixin). Embedding a widget in dijit.Form also causes this issue. The way it is now, you can't use any dijits from a different dojo instance inside of (at least) a dialog or form dijit, as they call the deprecated function.

In my case, I was embedding a web map inside a dialog, and I intended to handle the map myself.

Maybe a fix would be to use getChildren() instead of getDescendants() in dijit.Form and dijit._FormMixin, as well as other related areas? Your proposed change would also work fine for me.

comment:4 Changed 11 years ago by bill

Yup, recently I changed _FormMixin to use getChildren() in [25648], so it should work with multiple instances (albeit ignoring widgets from other dojo instances)... since you are handling the map yourself sounds like you are OK.

comment:5 Changed 11 years ago by kentonr

Bill, thanks for taking care of this!

Note: See TracTickets for help on using tickets.