editor.getSelected().toHTML() is not consistent
Question
Hi everyone,
I created a new component type, 'html-block', which is a component in which you can add your html code. I added an 'Edit' button to the toolbar, to enable the user editing the added html code. In order to show the html code of the component in the modal, I am using the function 'editor.getSelected().toHTML()';
The problem is that, sometimes the code returned is per example: <div><h1>h1</h1></div> (which is what I need, since I need the exact code that the user added at first), and sometimes it returns something like that: <div id='135'><h1>h1</h1></div> (with an id added automatically).
I also tried to use 'editor.getSelected().em.getHtml()' but the same issue occurred.
How can I solve that and retrieve the exact html code that the user entered ?
Thank you in advance.
Answers (3)
Inside your html-block component create a new property (eg. custom-code) for user's code and retrieve it with editor.getSelected().get('custom-code')
This solved the problem for me. Thank you.
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 #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>...
Issue #1661
I've created html table and cannot drag new elements to table cells
Hello. if I create html table with next block of code, everything works, I'm able to drop a Quote, for example, to any cell: But next code...
Issue #1466
Editing Saved html editor.setComponents slider load issue
I am working on a project where i integrated grapesJs for users to build there templates, save them in database and edit these saved templa...
Issue #384
Create and Edit Template into Database
This is my code to Create a new template and insert the inline html with style into the database : I am able to insert the template-data in...
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.