Custom component is not working after saving.
Question
Hi,
I have Button-Link custom component created, and when I dragged into canvas for the first time component is detecting its attributes and styles. But after saving the component and reloads the page, custom component type is missing from that component instead its showing Link type component. How to preserve the custom components even after saving?
Answers (3)
You should add some type to your component and then parse it in isComponent
For example the similar button link
const components = editor.DomComponents;
const link = components.getType('link');
components.addType('custom-link-button', {
model: link.model.extend({
defaults: Object.assign({}, link.model.prototype.defaults, {
attributes: { 'link-extended': 'custom-link-button },
}),
}, {
isComponent: (el) => {
let result;
if (el.tagName == 'A' && el.attributes['link-extended']
&& el.attributes['link-extended'].value === 'custom-link-button') {
result = {
type: 'custom-link-button',
editable: 0
};
// The link is editable only if, at least, one of its
// children is a text node (not empty one)
const children = el.childNodes;
const len = children.length;
if (!len) delete result.editable;
for (let i = 0; i < len; i++) {
const child = children[i];
if (child.nodeType == 3 && child.textContent.trim() != '') {
delete result.editable;
break;
}
}
}
return result;
}
}),
view: link.view
});@krishnaeverestengineering How are you saving and loading your work
Read the documentation please https://grapesjs.com/docs/modules/Storage.html
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1493
[QUESTION] render() works on the first time but not on subsequent calls
Hello, I've created a custom component that shows images using background-image on a <div> instead of using an <img> element. It's mostly w...
Issue #2136
[QUESTION] custom component type not found and traits not working after page load
Hi @artf I have created a very basic custom component named 'customsection' which uses traits to change the component's background-color by...
Issue #2417
API in Component not working after Deployment
Block.js => Component.js => We are able to call the API and it works in Deployment when we are passing the whole html with script, body, st...
Issue #2855
reload prev data for custome react component plugin after reload page
Hello @artf i am working with that awesome tool for long time i integrate it with react , and create a react plugin component for it , and...
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.