orion
orion

Reputation: 21

Fabric.js: can't get the active groups anymore

I'm using fabric 1.4.10 and i noticed that i can't get the active groups anymore! Everytime i call canvas.getActiveGroup() even when a group is selected, i get null.

My code to create groups:

var circle1 = new fabric.Circle({
  radius: 50,
  fill: 'red',
  left: 0
});
var circle2 = new fabric.Circle({
  radius: 50,
  fill: 'green',
  left: 100
});
var circle3 = new fabric.Circle({
  radius: 50,
  fill: 'blue',
  left: 200
});

var group = new fabric.Group([ circle1, circle2, circle3 ], {
  left: 200,
  top: 100
});

canvas.add(group);

Can anyone help please?

Upvotes: 2

Views: 3425

Answers (2)

AndreaBogazzi
AndreaBogazzi

Reputation: 14731

This is because you have to check for "activeObject".

fabric.canvas.getActiveObject() will return the current selected object.

getActiveGroup will return a group if there is a temporary group selection made with interactivity layer. ( mouse )

Upvotes: 3

Dark Horse
Dark Horse

Reputation: 161

You can add these two lines code to try:

canvas._activeObject = null;                    
canvas.setActiveGroup(group.setCoords()).renderAll();

Upvotes: 0

Related Questions