Open unclebay143 opened 1 month ago
For FamilyTree JS we use only onUpdateNode to update the database: https://balkan.app/FamilyTreeJS/Docs/GettingStarted#database
For FamilyTree JS we use only onUpdateNode to update the database: https://balkan.app/FamilyTreeJS/Docs/GettingStarted#database
Does that mean we cannot display a confirmation modal for delete? And can't prevent accidental delete through confirmation?
Deleted members are also deleted from the tree before the onUpdateNode
is triggered
No, you can have the same dialog, but you need to use on the onUpdateNode. You have the deleted nodes in args.
No, you can have the same dialog, but you need to use on the onUpdateNode. You have the deleted nodes in args.
that's the point, we can't intercept it, even if we show a confirmation modal, it gets deleted before the modal shows for instance my code looks like this.
Oh, I see... you need to return false if you don't have to delete the node.
family.onUpdateNode((args) => {
//post the data from args to your server
if (condition is met) {
return false
}
});
Ah, so close! Thanks @ZornitsaPesheva, able to achieve my thought now, the overall code now is as below:
familyTree.current.onUpdateNode(
(updatedTreeData: { removeNodeId: string }) => {
const isDeleteAction = !!updatedTreeData.removeNodeId;
if (isDeleteAction && !confirm("Do you want to delete?")) {
return false;
}
saveTree(updatedTreeData);
}
);
Similar to https://code.balkan.app/org-chart-js/dialog-on-save#JS