• Junaid Khader
  • NEWBIE
  • 0 Points
  • Member since 2014


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies

I have a lightning component where i use javascript to add/remove svg components based on user input.

After removing the svg components the second time, an exception is thrown: "NotFoundError: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node."

The reason for this is that the parentNode/parentElement property of the tag is null, but the tag is in the children-list of the parentnode.

I am wondering if i made a mistake or if this is a framework-bug.
The following simple example reproduces the error. The first button inserts the svg tag. The second button deletes all child-group-tags and inserts a new one.

When deleting a tag a second time, the error is thrown.

Does anyone know how to fix this?

Component:

<aura:component>
    <div><ui:button press="{!c.createSvg}" label="Create Svg Tag"></ui:button></div>
    <div><ui:button press="{!c.test}" label="Press 3x to create bug"></ui:button></div>
    <div id="funnel">Div for SVG</div>
</aura:component>
Client Controller:
({
	test : function(component, event, helper) {
	    var parent = document.getElementById("parent");
	    
	    helper.removeChildGroups(parent);
	    helper.addChildGroups(parent);
	},
	
	createSvg : function(component, event, helper){
	    //add svg tag
        var container = document.getElementById("funnel");
        var svg = document.createElementNS("http://www.w3.org/2000/svg", 'svg');
        var baseGroup = document.createElementNS("http://www.w3.org/2000/svg", 'g');
        baseGroup.id = "parent";
        
        svg.appendChild(baseGroup);
        container.appendChild(svg);
    },
})
Helper:
({
	removeChildGroups : function(parentTag) {
		var i;
		//iterate over children
		for(i = 0; i < parentTag.children.length; i++){
		    var child = parentTag.children[i];
		    //if g tag, remove
		    if(child.tagName == "g"){
		        if(child.parentElement == null && child.parentNode == null){
		            console.log("Here is the problem, child is in parent.children, but child.parent is null:");
                    console.log(child);
		        }
		        parentTag.removeChild(child);
		    }
		}
	},
	
	addChildGroups : function(parentTag) {
	    var groupTag = document.createElementNS("http://www.w3.org/2000/svg", 'g'); //Create a path in SVG's namespace
        var positionMarker = document.createElementNS("http://www.w3.org/2000/svg", 'circle'); //Create a path in SVG's namespace
        positionMarker.setAttribute("cx", Math.random()*50+50);
        positionMarker.setAttribute("cy", Math.random()*50+50);
        positionMarker.setAttribute("r", 10);
        
        groupTag.appendChild(positionMarker);
        parentTag.appendChild(groupTag);
        
	},
})
 

 

I am a bit of a beginner at formulas, so hopefully one of you will think this is easy, and be able to help. :-)

 

Customer requirement:

 

Create a formula field that displays the Week Number (as Week 1, Week 2, etc), based on the Date entered on a particular record (same object).

 

Ex: 01/01/09 - 01/04/09 would return a value of "Week 1"  

01/05/09 - 01/11/09 = Week 2

01/12/09 - 01/18/09 = Week 3

 

and so on.....

 

Is using the CASE function the way to go, and if so, what's the shortest way to create this formula?

 

Thank you in advance!

S

 

  • April 20, 2009
  • Like
  • 0