grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

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

Open konstantin55000 opened this issue 8 years ago • 3 comments

Hi everyone, let say i've added block

on canvas. When i adding next (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 ) Please look at http://prntscr.com/ij8c82 Thank you , for help.

konstantin55000 avatar Feb 24 '18 19:02 konstantin55000

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);
        }
    }
});

konstantin55000 avatar Feb 24 '18 21:02 konstantin55000

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

ionic666 avatar Jun 11 '18 06:06 ionic666

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.

lock[bot] avatar Sep 17 '19 13:09 lock[bot]