Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make objects in canvas unselectable?

I want to make all object in canvas unselectable. I've found selectable method but i didn't find the way to implement it to all objects.

like image 923
Yevgen Avatar asked Jul 23 '12 20:07

Yevgen


3 Answers

I was looking for an unmovable and uneditable Fabric Text and I finally found a solution combining several SO, hope I can save someone some time.

Using "selectable": false wasn't enough in my case : the text was still editable and the cursor was still the "movable cursor" (even if the object wasn't selectable).

I had to add "evented": false. Here is an example:

this.canvas.add(new fabric.Text("Hello world !", {
            "selectable": false,
            "evented": false
}));

You can play with different control options here : http://fabricjs.com/controls-customization

like image 62
Emerica Avatar answered Nov 05 '22 12:11

Emerica


You can make all the elements un-selectable using below code

canvas.deactivateAll();
canvas.renderAll();
canvas.forEachObject(function(object){ 
       object.selectable = false; 
});
like image 28
Jitendra Pawar Avatar answered Nov 05 '22 11:11

Jitendra Pawar


There is a way like this in option -

selectable: false

      or 

object.set({selectable:false})

      or


 object.selectable = false;
like image 7
rafi Avatar answered Nov 05 '22 11:11

rafi