Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change text once it is added on canvas

In fabric-js, i am making Group of Rect and text field and then adding it to the canvas. i am using following code , but can i change the Text of text field once it is added in canvas .

I have made Fiddle Please Check,

http://jsfiddle.net/HAb4N/5/

var canvas = new fabric.Canvas('c');

var Bar = new fabric.Text('Bar', {selectable: false, top: 50, left: 10});


var rect = new fabric.Rect({width: 100, height: 100, left: 100, top: 100, fill: 'red'});
var group = new fabric.Group([rect, Bar], {selectable: true, top: 50, left: 100});
canvas.add(group);

canvas.renderAll();

$(document).click(function(e) {
    console.log('click');
    console.log('ActiveObject', canvas.getActiveObject());
    console.log('ActiveGroup', canvas.getActiveGroup());
    Bar.set('Text','Selectedoooooooo');
});
like image 702
anam Avatar asked Dec 07 '22 05:12

anam


1 Answers

This works for me:

Bar.setText("my_text");
canvas.renderAll();
like image 116
ilgam Avatar answered Jan 02 '23 07:01

ilgam