Issue #577Opened November 28, 2017by krunal0392 reactions

Only allow one component of specific type on editor

Question

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

Answers (3)

ryandebaNovember 28, 20171 reactions

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.

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

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

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.