Issue #915💬 AnsweredOpened February 28, 2018by JulyanoF0 reactions

Enable confirmation box when remove block

快速解答by artf

Nope, but you can extend the default tlb-delete command

Read full answer below ↓

Question

Is there any option to activate a confirmation box before delete any block?

Answers (3)

artfMarch 2, 2018

Nope, but you can extend the default tlb-delete command

editor.Commands.add('tlb-delete', ed => {
	if (confirm('Sure?')) {
		const selected = ed.getSelected();
		selected && selected.destroy();
	}
});
IceweexMarch 25, 2018

@artf this works only for toolbar button, but when I hit "delete" on my keyboard it doesn't. How can I override this event?

artfMarch 29, 2018

Hi @Iceweex, unfortunately, at the moment, you can't. For the next release, I'll centralize those commands and will update also its event lifecycle, so in that case, you'll able to achieve the task in this way

	const commandName = 'core:component-delete';
    editor.on(`run:${commandName}:before`, (options) => {
	  console.log(`BEFORE ${commandName}`);
      if (!confirm('Are you sure')) {
        options.abort = 1; 
      }
    });
    editor.on(`run:${commandName}`, (deleted, options) => {
      console.log(`AFTER ${commandName}`, deleted);
    });
    editor.on(`abort:${commandName}`, (options) => {
      console.log(`ABORT ${commandName}`);
    });

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.