Issue #1617Opened November 29, 2018by coder-strange3 reactions

[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)

artfDecember 1, 20183 reactions

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);
	}
})
lock[bot]December 1, 20190 reactions

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.

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.