Card Deletion in Kanban

Asked by Anonymous
1 years ago.

If we enable the delete button on the cards once clicked even with modal showing and cancelling the operation, the card is removed fom the UI.

Comment posted by Dan Letecky [DayPilot]
1 years ago.

Could you please post your onCardDelete implementation?

Comment posted by Anonymous
1 years ago.
const modal = await DayPilot.Modal.confirm("Delete this Task?");
if (modal.canceled) {
  return;
}
Comment posted by Dan Letecky [DayPilot]
1 years ago.

At this moment, onCardDelete doesn’t support asynchronous processing. With the current version, you would have to use the built-in confirm() dialog which is synchronous:

onCardDelete: args => {
    const result = confirm("Delete this Task?");
    if (!result) {
        args.preventDefault();
    }
}

I’ve added the async handling to the wishlist, so in the future you will be able to use something like this:

onCardDelete: async args => {
  args.async = true;
  const modal = await DayPilot.Modal.confirm("Delete this Task?");
  if (modal.canceled) {
    args.preventDefault();
  }
  args.loaded();
}
Comment posted by Anonymous
1 years ago.

Is there anyway for us to get control of the deletion process so that we can do some other tasks or do we have to use the process as shown above?

Comment posted by Dan Letecky [DayPilot]
1 years ago.

At this moment, no.

Soon, the Kanban component will support an onBeforeCardRender event which will let you add custom icons using active areas. You can define a custom click event handler for active areas where you can implement your own logic.

This will allow defining a custom delete button (your icon at the specified position, with your own onClick handler).

Answer posted by Dan Letecky [DayPilot]
1 years ago.

Actually, you don’t need the async support to make this work. You just need to switch the logic: Cancel the default action first and delete the event manually if the user confirms the action:

onCardDelete: async args => {
  args.preventDefault();
  const modal = await DayPilot.Modal.confirm("Delete this Task?");
  if (modal.canceled) {
    return;
  }
  kanban.cards.remove(args.card);
}
Comment posted by Anonymous
1 years ago.

Great.

If you delete a card via the context menu or the delete button you get 2 different arguments.

One has a source and the other has a crad property.

It would be nice if both returned the same so that we don’t have to check this in code. (maybe!)

Comment posted by Dan Letecky [DayPilot]
1 years ago.

The context menu is universal and it receives different source objects, depending on the source element. So unfortunately it has to stay this way.

This question is more than 1 month old and has been closed. Please create a new question if you have anything to add.