2

I am trying to change the font attribute for text in fabric.js.

Here is my fiddle: http://jsfiddle.net/mvprzy/szzGa/

I believe this part of the fabric script should work, but isn't:

var fontControl = $('font-control');
fontControl.onchange = function () {
    fabric.Text.set('fontFamily', font-control.value);
    canvas.renderAll();
};

What am I doing wrong?

kangax
  • 38,898
  • 13
  • 99
  • 135
mvprzy
  • 105
  • 1
  • 6

1 Answers1

6

Try this

First of all you need to include jQuery in the jsfiddle (: After that all I did was make the fabric.IText a variable and change the on change function to the following based on this SO post

var fontControl = $('#font-control');
$(document.body).on('change', '#font-control', function () {
    text.fontFamily = fontControl.val();
    canvas.renderAll();
});
Zach Saucier
  • 24,871
  • 12
  • 85
  • 147
  • Thanks - had not noticed that jQuery was not included, sheesh. Had tried text as var earlier but was not going - that document.body tip did the trick.. Awesome. – mvprzy Jun 22 '14 at 18:33