Reputation: 2973
I am trying to select multiple and delete. Selecting one object deletes just fine but when selecting multiple it doesn't do anything. I have looked around and seen this answer with a fiddle which works in v1.4
https://stackoverflow.com/a/41286840
When I select multiple I get
canvas.getActiveGroup is not a function
Now as the getActiveObject can go from an array. I tried to check if greater than one using length and then deleting those objects but it always goes through the
if (activeObject) {
instead of
else if (activeObject.length >= 2) {
But neither will work. Doesn't Fabric have a function with multiple selected items?
Upvotes: 1
Views: 662
Reputation: 797
canvas.getActiveGroup was removed in the new versions. so here's the code work fine. try this. more information about fabricJs changes click to refer this fabricJS breaking changes
deleteSelectedObject() {
let activeObject = this.canvas.getActiveObjects();
if (activeObject) {
let objectsInGroup = activeObject;
this.canvas.discardActiveObject();
let self = this;
objectsInGroup.forEach(function(object) {
self.canvas.remove(object);
});
}
}
Upvotes: 0
Reputation: 15604
As it is mentioned on change log getActiveGroup
this function is removed now.
So you need to get the object using canvas.getActiveObjects()
then loop through the objects present and remove them from canvas.
Here is jsFiddle
Upvotes: 2