I added one component named template in the blocks but when i try to drag another components inside this template component ,it will be dragged but after saving it removes all the components inside it. How to avoid this?
Question
This is code of template component:
export default {
init(editor) {
editor.DomComponents.addType('myTemplate', {
isComponent: el => el.tagName == 'template',
model: {
id: 'template',
defaults: {
tagName: 'template',
hoverable: true,
resizable: {
minDim: 20,
tc: 1, // Top handler
cl: 1, // Left handler
cr: 1, // Right handler
bc: 1 // Bottom handler
},
// As by default, traits are binded to attributes, so to define
// their initial value we can use attributes
attributes: {
'data-gjs-type': 'myTemplate'
}
}
},
view: {
// eg. You can customize the tag in the canvas
// By default, the view will use the same tag of the model
tagName: 'div',
// onRender() {
// this.el.innerHTML = `<div data-gjs-type="divWrapper" style="min-height:60px;"></div>`;
// }
}
});
editor.BlockManager.add('myTemplate', {
label: `<div class="mdi mdi-table"></div>
<label class="gjs-block-label">Template</label>`,
category: 'Components',
attributes: { class: 'gjs-block-section' },
// Select the component once it's dropped
select: true,
// This triggers `active` event on dropped components and the `image`
// reacts by opening the AssetManager
activate: true,
content:
'<template style="width:100%" data-gjs-type="myTemplate"></template>'
}); }};
I debugged it, so i got that : setComponents method in the dom_components clearing it ...but not getting why it is removing?
setComponents(components) {
this.clear().addComponent(components);
}
setComponents calls clear method which is responsible for removing elements inside it
clear() {
this.getComponents()
.map(i => i)
.forEach(i => i.remove());
return this;
}
I commented this so it was working fine and persisted the components inside component ...is there any way to avoid this?
Answers (1)
<template> tag should be treated differently #244
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3228
Component Value is not changing
Hi @artf I've added a new component here is the code on selecting the h1 and h2 tag it's changing the value in the HTML section as you can...
Issue #2614
[QUESTION] Recursive view update of custom component
Hi, I have defined a custom type like: I want to keep the customTag in my model and show the content (HTML) in the view. However, in the co...
Issue #2212
Extending default image component, resizable properties ignored
I'm trying to extend the default image component. I can see my "Test" trait, so I assume that the component is correctly overridden, but th...
Issue #3225
How to Update Style from checkbox Trait?
Hi @artf I am trying to update the style using the checkbox trait but it's not calling the function. Here is the code I really appreciate a...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins →Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.
Browse premium plugins →Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.