addType in domcomponent for html conditionals generates a <div> in visualization
Question
I have followed the instructions from issues #37, #787 , #208 , #1254
The comments are there in the HTML, however an "<div>" element is created on visualization,
how do we change the code so that this "<div>" could be replaced by something else, or add a style ?
Ex: "<div style="display:none"></div> would be ok.
I've tried to change the defaults for the new type but with no effect.
I'm using the latest release (0.14.21) in my local copy (linux, firefox)
Answers (2)
Find the answer myself, for anyone that may have the same problem : extend the render part and set a display:none to the object to be rendered, this will not affect the html.
var textnodeType = domc.getType('textnode');
domc.addType('comment', {
model: textnodeType.model.extend({
toHTML() {
return `<!--${this.get('content')}-->`;
},
},{
isComponent(el) {
if (el.nodeType == 8) {
return {
tagName: 'NULL', // just need this to avoid some parser rule
type: 'comment',
content: el.textContent
}
}
},
}),
view: textnodeType.view.extend({
render: function () {
this.el.style.display = "none";
return this;
}
}),
});
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 #1254
addType in domcomponent for html conditionals doesn't work grapesjs 0.10.7 version
Hi Artur, First of all, thank you for sharing such a great project :) I want to tell you a problem that I have experienced. You commented b...
Issue #1877
[FEATURE REQUEST] Custom styles that add/remove custom classes?
Currently, all the style manager values that you change for an element simply update a <style> tag inline in the HTML. Is it possible to ch...
Issue #1787
[Question] Change HTML of Panel buttons from span to button
I have created some Panels and would like to change the element of panel buttons from span to button as its more appropriate and looks bett...
Issue #563
Table <thead> and <tbody> tag gets Omitted
Hello, There is new issue with GrapesJS (maybe). I've created new component using bm.add() in which I've used a table element with <thead>...
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.