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 ca
Solution 1:
This works for me:
Bar.setText("my_text");
canvas.renderAll();
Solution 2:
When using the "set" function try camelcase for the first argument!
In other words change:
Bar.set('Text','Selectedoooooooo');
to:
Bar.set('text','Selectedoooooooo');
This works for me 🙏🏼
Solution 3:
Use the new IText in FabricJS. Here is a nice solution
This is my answer to it
addText(color) {
color = color ? color : '#333';
let textEl = new fabric.IText('', {
fontFamily: 'Open Sans',
fill: color,
fontSize: 50
});
this.canvas.add(textEl).setActiveObject(textEl);
textEl.enterEditing();
}
Solution 4:
Yes you can set text once it is added to canvas.Here is the jsfiddle
try changing your
Bar.set('Text','Selectedoooooooo');
to
Bar.setText('Selectedoooooooo');
Hope it helps....
Solution 5:
You can access children of a group via getObjects()
or item()
methods:
canvas.on('object:selected', function(e) {
e.target.item(1).setText('Selectedoooooooo');
});
Post a Comment for "Change Text Once It Is Added On Canvas"