Issue #577πŸ’¬ AnsweredOpened November 28, 2017by krunal0392 reactions

Only allow one component of specific type on editor

Quick answerby ryandeba❀ 1

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 us...

Read full answer below ↓

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)

ryandebaβ€’ November 28, 2017

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.

bunomonteiroβ€’ December 30, 2017
editor.on('component:add', model => {
    // ... your logic goes here
    if(remove){
        model.destroy();
    }
  });
artfβ€’ November 30, 2017

@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...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins β†’
Premium option

Premium plugins ship with support, regular updates, and production-ready features β€” save days of integration work.

Browse premium plugins β†’

Related tutorials

In-depth guides on the same topic.

All tutorials β†’

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.