Issue #1813💬 AnsweredOpened February 19, 2019by ateebahmed0 reactions

Can't get correct component from editor.on events callback

快速解答by artf

You're doing something wrong, works as expected here https://jsfiddle.net/nfkha41p/ Next time, create a reproducible demo first, then open an issue...

Read full answer below ↓

Question

I am using editor's events to get component after some action like component:add, block:drag:stop, but in both events I can't get my component that I dragged on canvas.

when I call component.is('my-component-type'), it gives false, I need to perform actions based on its type, which I can't when I get that from event's callback, but if I select a component and register listener on component:selected, I get the right type, how can I have this behaviour with other events?

Answers (3)

artfFebruary 22, 2019

You're doing something wrong, works as expected here https://jsfiddle.net/nfkha41p/

Next time, create a reproducible demo first, then open an issue...

ateebahmedFebruary 22, 2019

Actually I can't produce it with built-in components but I'm using a custom component which extends default text component, will paste the code as I could not find which property to set to get the component type, although I had set type: 'my-type' in BlocksManager.

naveen-15697November 11, 2019

You're doing something wrong, works as expected here https://jsfiddle.net/nfkha41p/

Next time, create a reproducible demo first, then open an issue...

@artf Here, when I drag a first component, I get three alerts. But I need only the parent component. i.e, the first alert. Is there any solution?

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...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.