Replacing selected text and getting html
The content of the model is actually updated once you blur from the editable component, so when you call getHtml it's just not yet there
Read full answer below ↓Question
Hi! Im trying to replace selected text with a code (random code). It's works, i can see the code, but when i do editor.getHtml() not. If i deselect the component (selecting another one) the change takes effect.
var rte = editor.RichTextEditor;
rte.add('replace-text', {
icon: '<b>${var}</b>',
attributes: {title: 'Replace Text'},
result: function(rte) {
const codeToReplace = makeid(10);
rte.exec('insertText', codeToReplace); // works
//some magic();
console.log(editor.getHtml()); //no showing the change.
}
});
Thanks!
Answers (2)
The content of the model is actually updated once you blur from the editable component, so when you call getHtml it's just not yet there
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 #1511
[QUESTION] Change the html content of the selected component
I am trying to replace the html of the basic Text componet using the below code const component = editor.getSelected(); component.set('cont...
Issue #1669
[Question] Custom link modal doesn't update the current text but add another text with link
Hello Artur, I'm trying to have a custom modal when clicked link button in RTE. but it doesn't convert selected text to link but what it do...
Issue #1616
grapesjs editor.gethtml() not work in Edge Explorer
In my project i'm using this code to get the html from the grapesjs editor: var html = window.frames[0].editor.getHtml(); my editor is in i...
Issue #1930
[QUESTIONS] change 2 attributes with 1 trait
I have an input trait, I want to change the 2 attributes (name and type) on the selected input element, on canvas is appropriate, but in th...
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.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.