I am trying to delete group in fabric js (version: 2.0.0-beta.7).
But its only work for single object, so how to fix it so it can delete all selected objects?
$('.delete_object').click(function(){
var activeObject = canvas.getActiveObject();
if (activeObject.type==='activeSelection') { //For Group selection
if (confirm('Are you sure?')) {
var objs = [];
activeObject.forEach(function(o) {
objs.push(o);
});
canvas.remove(...objs);
}
}
else if (activeObject) {
if (confirm('Are you sure?')) {
canvas.remove(activeObject);
}
}
});
codepen: https://codepen.io/dhavalsisodiya/pen/bLQxKo
steps
1) Try to add 2 or more objects
2) Select some of them
3) Now try to delete it, it will through this error: TypeError: activeObject.forEach is not a function