[Question]How to change custom component content (html) from ajax?
Question
Hi @artf,
First of all thanks for this awesome plugin.
Can you please let me know how i can update/change block content?
I created custom block + component.
<table><tr><td class="some-class">text_to_replace</td></tr></table>
Component has new toolbar button (search icon in attached screenshot) and on click i get new info like product_name etc.
So, i get current block html, do all stuff ...
block_html = editor.getSelected().toHTML();
new_html = block_html.replace(.....);
How can i update selected block html to new text?
something like
editor.getSelected().setHTML(new_html);
If i try to change from Model
components.addType('product', {
model: default_model.extend({
defaults: Object.assign({}, default_model.prototype.defaults, {
toolbar: [.......],
.....
}),
setProductInfo(json) {
console.log(json);
this.set('style', {color: '#ff0000'}); // <=== color is changed to red
// how to change content instead of color ?
}
}
Block code look like this:
smc_block_manager.add('product-block', {
label: 'Product - Main',
category: block_category_product,
attributes: {
class:'fa fa-tag'
},
content: {
type: 'product',
components: product_item,
activeOnRender: 1
}
});
I also tried
editor.getSelected().components('new html here');
but seems is added new component inside old component.
Thank you

Answers (2)
The components() method is the way to go to change the inner content editor.getSelected().components('<div>New inner content</div>'); but take care that with editor.getSelected().toHTML() you're getting the outer content (with its component tag)
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 #1537
Duplicate component not style
Hi, First of all, thanks a lot for the awesome work ❤️ !!! I've a question about the duplication tool so here the steps to follow :I drag&d...
Issue #1497
Inner element content change with pop-up
Hello @artf I've make pop-up for select custom link data with image. Now all the data reflected properly but when I try to change src than...
Issue #1077
How we can remove the selected component html
Hi artf, Please let us know how we can remove the selected component html like I have one button html and when i selected that "gjs-comp-se...
Issue #1296
Custom Rich Text Editor is not working
Hi @artf, I've just created a custom plugin of the RTE using different libraries like CKEditor 5, TinyMCE 4 or pell but all of them with th...
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.