Opened 7 years ago
Closed 7 years ago
#17548 closed defect (duplicate)
_Container addChild function is not working properly
Reported by: | pnongah | Owned by: | |
---|---|---|---|
Priority: | undecided | Milestone: | tbd |
Component: | Dijit | Version: | 1.9.1 |
Keywords: | Cc: | ||
Blocked By: | Blocking: |
Description
We get a refNode is null at line 42 as shown below:
addChild: function(/*dijit/_WidgetBase*/ widget, /*int?*/ insertIndex){ // summary: // Makes the given widget a child of this widget. // description: // Inserts specified child widget's dom node as a child of this widget's // container node, and possibly does other processing (such as layout). // I want to just call domConstruct.place(widget.domNode, this.containerNode, insertIndex), but the counting // is thrown off by text nodes and comment nodes that show up when constructed by markup. // In the future consider stripping those nodes on construction, either in the parser or this widget code. var refNode = this.containerNode; if(insertIndex > 0){ // Old-school way to get nth child; dojo.query would be easier but _Container was weened from dojo.query // in #10087 to minimize download size. Not sure if that's still and issue with new smaller dojo/query. refNode = refNode.firstChild; /* line 42 */ while(insertIndex > 0){ if(refNode.nodeType == 1){ insertIndex--; } refNode = refNode.nextSibling; } if(refNode){ insertIndex = "before"; }else{ // to support addChild(child, n-1) where there are n children (should add child at end) refNode = this.containerNode; insertIndex = "last"; } }
A simple solution to that would be to check for refNode in the "while" as follow:
/* line 42 */ while(refNode && insertIndex > 0)
Note: See
TracTickets for help on using
tickets.
Duplicate of #16874.
Presumably you have passed illegal arguments to addChild(), although I can't say for sure without a test case.