Search code examples
javascripthtml5-canvasfabricjs

FabricJS Delete multiple object in V.2


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?


Solution

  • 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