Custom component is not working after saving.
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.defaul...
Read full answer below β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 #6685
Custom component styles are not applied after deletion and re-addition
GrapesJS version [x] I confirm to use the latest version of GrapesJS What browser are you using? Chrome v143.0.7499.193 Reproducible demo l...
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...
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 βRelated tutorials
In-depth guides on the same topic.
Tutorial
How to Build a Production GrapesJS Editor: The Complete Walkthrough of Brief, Preset, Plugins, and Services
A complete walkthrough of building a production GrapesJS editor: how to choose a preset, pick plugins, and scope setup services without burning a sprint.
Tutorial
GrapesJS Inline RTE Plugins Update: CKEditor 5 v0.1.4 and Froala Inline Text Editor
CKEditor 5 Inline for GrapesJS v0.1.4 fixes Studio SDK toolbar clipping, iframe injection and link balloon bugs. Compare with Froala Inline β both $69.
Tutorial
Embed GrapesJS in Your SaaS: A Weekend Guide
Embed GrapesJS in your SaaS and ship a white-label page builder over a weekend. Honest tradeoffs, real code, and the plugins that close the UX gap.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.