willowsystems / jSignature

jQuery plugin - draw signature in browser.
720 stars 266 forks source link

What exactly does setData do? Is it possible to import previously saved signature data into the jsignature widget on page load? #66

Open seport opened 8 years ago

seport commented 8 years ago

I have a rails web app which stores signatures in a database. Each entry in the database is editable and when you pull up the edit page for a particular entry with an existing signature, I'd like to initialize the jSignature widget with the existing signature on file.

According to some sleuthing on stack overflow and looking at your documentation it looks like

$sigdiv= $("#signature") $sigdiv.jSignature("setData","data:image/jsignature;base30,cVZ1000Y59ce1Gomn1Sla4331222_2Q9aad331000000062344544")

should initialize the widget with some signature displayed automatically. However, this is breaking the widget (resulting in an empty #signature div). Based on your documentation it's not totally clear to me whether I'm even using setData for its intended purpose.

icnatejackson commented 8 years ago

@seport you must have something else messed up. doing exactly what you provided produces an signature for me. Just make sure you've initialized the component first:

$sigdiv= $("#signature");
$sigdiv.jSignature();
$sigdiv.jSignature("setData", "data:image/jsignature;base30,cVZ1000Y59ce1Gomn1Sla4331222_2Q9aad331000000062344544") ;
seport commented 8 years ago

Strange... what do you mean by initializing the component first? I thought that was just var $sigdiv = $("#signature") ? Or in my case

var $sigdiv;
$sigdiv = $("#signature")

I'll play with it again tonight...

icnatejackson commented 8 years ago

@seport the following line of jquery only gets a reference to the DIV that will be used to host your jSignature component:

$sigdiv = $("#signature") ;

The Initialize comment I made before just means to call this line of code first:

$sigdiv.jSignature();

And then, after that, you can call the setData method with this line:

$sigdiv.jSignature("setData", "data:image/jsignature;base30,cVZ1000Y59ce1Gomn1Sla4331222_2Q9aad331000000062344544") ;

seport commented 8 years ago

Oh I see. I think I did call that first, but I'll try it again and report back. Thanks for your help!