Issue #955Opened March 15, 2018by alexroosenstein1 reactions

[Question]: Find component associated with HTML element in iframe/visual editor.

Question

Hi!

I'm working on an implementation of GrapesJS where I can a drag&drop a piece of text from outside GrapesJS into an existing text element/component. I don't use the drag&drop functionality of GrapesJS for this, but the native (browser) drag&drop.

I have some code working for this, a working drag & drop, and I can change the text in the visual editor (inside the iframe). But this doesn't change the actual content of the document, as they are processed/stored in the background (in components, correct?).

Now I'm looking for a way to find the component associated with a HTML element, so I can push the text in that component.

I hope that is clear! I tried looking for existing issues about this, and I found many about updating the content of components, but not a good clue to how to actually get the component I want to update...

Answers (3)

artfMarch 17, 20181 reactions

You can query the wrapper to get component models, eg.

const component = editor.DomComponents.getWrapper().find('#somid')[0];
component.components(`<div>Add some content inside</div>`);

BTW it's not clear why the content is not updating while you say I can change the text in the visual editor (inside the iframe)

alexroosensteinMarch 17, 20180 reactions

Thanks! I'll give it a go tomorrow.

By the way, I update the text via JQuery using the text() function, but when I move the element to a different position the original text reappears again.

japo32September 3, 20190 reactions

I had the same issue where I move the component with drag and drop. My solution was to add a text component inside my custom component. :)

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.