Is it possible to restrict that only one of a certain component can be added to the canvas?
Question
We want to define a custom component that may or may not be added into the HTML, but we want to disallow adding more than one of that component. Can this restriction be done in GrapesJS?
Answers (2)
Not something built-in, but definitely achievable by using the GrapesJS's API
Extremely easy would be adding a listener (eg, change:changesCount), search your component and then apply your logic
editor.on('change:changesCount', () => {
editor.getComponents().each(model => ...)
})
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.
Issue #577
Only allow one component of specific type on editor
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 t...
Issue #459
Error when including a custom component inside another block
Sorry for the vague title. I'm not sure how to describe this concisely. I have a custom block where i want to restrict that only images can...
Issue #2008
[Question]The canvas turns dark and unmodifiable on adding a large piece of custom html.
I used to add custom html with editor.addComponent(). It works well at most of the time, but when I try to insert a large piece of HTML whi...
Issue #1951
[QUESTIONS] change or add event on add component from block
is it possible ?, change the drag and drop event to on click when adding a new component, I want to add components by clicking the block th...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.