[QUESTION] Custom component property that is not a trait
Question
I would like to create a custom component with a property that will be updated by specific code, but I don't want this property to be visible and updatable as a trait; let say my property is called "ebTesto", I wrote a plugin function like that:
function addComponentX(editor, options){
const COMPONENT_TYPE = 'eb-componentx';
editor.DomComponents.addType(COMPONENT_TYPE, {
isComponent: function(el) {
if(el.getAttribute && el.getAttribute('data-gjs-type') ==COMPONENT_TYPE) {
return {type:COMPONENT_TYPE};
}
},
model: {
defaults: {
ebTesto: 'Ciao',
tagName: 'div',
components: [
{
type:'text',
content: 'Title component X',
removable: false
}
]
},
ebTesto: 'Ciao'
}
});
editor.BlockManager.add(COMPONENT_TYPE, {
label: 'Component X',
category: 'EB',
attributes: {class:'eb-componentx-block'},
content: `<div class="eb-componentx" data-gjs-type="${COMPONENT_TYPE}"></div>`
});
}
I expected to find my new property in the "gjs-components" part of the stored JSON, but this is what I got:
[
{
"type": "eb-componentx",
"classes": [
"eb-componentx"
],
"components": [
{
"type": "text",
"removable": false,
"content": "Title component X"
}
]
}
]
Maybe I'm trying the wrong way? Has anyone ever had a similar need? Thanks for your help!
Answers (3)
Thank you both!
I think it's not stored since the property hasn't been changed from the default. The editor should be able to recover the property from the component definition itself.
Try adding it inside defaults
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3019
[QUESTION] - Bind inner text/html (like div, p, h1) to Trait
Hi! I've created a custom trait, and I want to be allowed to change the content of the tags (in this case it's a H1 tag) based on the trait...
Issue #2744
[QUESTION] Disable a block drag&drop
Hello everyone, I would like to make forbidden the drop of one block before another specific one. Context : i've create a new trait for som...
Issue #1144
[Question]: Custom property to change multiple settings
Is there a way to extend a current property or create a new one to change multiple properties? I have a component in which I would like to...
Issue #1297
[QUESTION] Is Multiple trait possible to do editable img and <a> tag in the table component?
Hi Artur, I had forgot to say i am using latest version, i am sorry for that. I want to add a plugin for editable social media icons, image...
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.