grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

Only allow one component of specific type on editor

Open krunal039 opened this issue 9 years ago • 5 comments

is there way to not allow to drop any specific component more than one time on page? I have custom component and user cannot drop it more than one on page, so if component is already added on page then I want to display specific message and not allow to be dropped in editor

krunal039 avatar Nov 28 '17 10:11 krunal039

Hi @krunal039,

My best suggestion would be to listen for the component:add event. In the event listener function you could check to see if the added component is the type that you are looking for, and if more than one of those components now exist in the canvas then remove the one that was just added and inform the user.

ryandeba avatar Nov 28 '17 14:11 ryandeba

@krunal039 Ryan's suggestion is the correct way to accomplish your request

artf avatar Nov 30 '17 12:11 artf

@artf @ryandeba thanks for reply, can you please let me know where can I listen event for component:add

krunal039 avatar Nov 30 '17 15:11 krunal039

editor.on('component:add', model => {
    // ... your logic goes here
    if(remove){
        model.destroy();
    }
  });

bunomonteiro avatar Dec 30 '17 17:12 bunomonteiro

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 18 '19 03:09 lock[bot]