Issue #897Opened February 24, 2018by konstantin550001 reactions

How to: find some component at canvas, on event "component:add"

Question

Hi everyone, let say i've added block <form> on canvas. When i adding next <form> (second time) , need to check: if weather this component already present on canvas, call function implodeComponents(presentedComp, recentlyAddedComp){}

But, On event editor.on('component:add'... i can work only with recently added component. The question is : how to traverse through all components on canvas, to find special component (example <form>) Please look at http://prntscr.com/ij8c82 Thank you , for help.

Answers (3)

konstantin55000February 24, 20181 reactions
Code SnippetTEXT
Thanks for your attention. 
I just read the doc.
And ended up with this solution:


 editor.on('component:add', function(currentComp) {  
 
        if (currentComp.attributes.tagName == "form"){

            var modelList =  (domComps.getComponents()).models;            
            var presentForms = modelList.filter(function(component) {
              return component.attributes.tagName == "form";
            }); 
            
            if (presentForms.length > 1){
                //console.log("canvas have > 2 forms");
                implodeComponents(currentComp, presentForms);
            }
        }
	});
ionic666June 11, 20180 reactions

@konstantin55000 hi ,bro ,domComps.getComponents() is getting all models,i just want to get button.how can i do it?thanks

lock[bot]September 17, 20190 reactions

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.