Issue #906Opened February 28, 2018by ciotuvasile0 reactions

[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

gjs

Answers (2)

artfApril 15, 20180 reactions

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)

lock[bot]September 17, 20190 reactions

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.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.