[Question]: Can't get correct component from editor.on events callback
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)
You're doing something wrong, works as expected here https://jsfiddle.net/nfkha41p/
Next time, create a reproducible demo first, then open an issue...
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.
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.
Issue #1814
[Question]: How to fire event which triggers component:selected with my component
I want to select my component whenever it is dragged from blocks to canvas and rendered, I have tried with registering events on component:...
Issue #1875
[QUESTION] ID changes when importing html or passing html in components prop in config.
Hi, I built a component and block that I can drag and drop in the canvas. My issue is that some styles rely on the ID. I know this might no...
Issue #1831
[Question] How to run command for a block component?
I'd like to do something like this. so once a user drops the test component into the canvas, I'd like to open up asset manager modal where...
Issue #1990
[QUESTIONS] need to call method before remove the html component
Hi, I need to call the method before remove the HTML component. how can I do that calling method like editor.on('block:drag:stop', function...
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.