[Question] How can I stop the drop from block:drag:start event? Also is there any event to listen Invalid target position?
Question
First of all, I really appreciate your replies on my questions. Thank you for all.
Question 1 : I've a situation where if a particular block is already in the canvas, I can't let that block to be added again. What I'm doing is, I'm listing to block:drag:start and compares if the component is already dropped (in gjs-components), I got success till now, but how to prevent the drag event right there?
Question 2 : When a component is bound to specific tag/component, where can listen when the invalid drop happens?
Answers (2)
Question 1 : I've a situation where if a particular block is already in the canvas, I can't let that block to be added again. What I'm doing is, I'm listing to block:drag:start and compares if the component is already dropped (in gjs-components), I got success till now, but how to prevent the drag event right there?
I'd suggest to move this logic to components. So create a new component type (eg. my-cmp) and setup few listeners:
editor.on('component:add', component => {
if (component.is('my-cmp')) {
editor.BlockManager.get('my-cmp-block') // eg. hide the block
// ...
}
});
editor.on('component:remove', component => {
if (component.is('my-cmp')) {
editor.BlockManager.get('my-cmp-block') // eg. show the block
// ...
}
});
Question 2 : When a component is bound to specific tag/component, where can listen when the invalid drop happens?
Currently you can do it only via sorter:drag:end event
editor.on('sorter:drag:end', (targetCollection, modelToDrop, errors) => {
if (errors.length) {
console.log('errors', errors);
}
})
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.
Issue #905
[Question] need to find nessesary event.
Hello to all! When dragging block into canvas, and drop it: ... we have an event to detect, what block we drop in. ?: but when i drop block...
Issue #1464
Customizing the Component Position
First of all thank you guys for this awesome library, And I have one Clarification that is how do i customize the drop position example if...
Issue #1951
[QUESTIONS] change or add event on add component from block
is it possible ?, change the drag and drop event to on click when adding a new component, I want to add components by clicking the block th...
Issue #1683
How to change id/class when new element drop on editor or render element with dynamic ip?
Hello @artf , Hope you are doing well. I have two questions regards dynamic blocks adding, 1) Is it possible to render the block with dynam...
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.