grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

[Question]: Can't get correct component from editor.on events callback

Open ateebahmed opened this issue 7 years ago • 3 comments

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?

ateebahmed avatar Feb 19 '19 21:02 ateebahmed

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 avatar Feb 22 '19 14:02 artf

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.

ateebahmed avatar Feb 22 '19 14:02 ateebahmed

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?

naveen-15697 avatar Nov 11 '19 07:11 naveen-15697