brinley / jSignature

jQuery plugin for adding web signature functionality
http://www.unbolt.net/jSignature
690 stars 529 forks source link

setData not working first time called #187

Closed JamesInWA closed 2 years ago

JamesInWA commented 3 years ago

I am using jSignature in a modal window and saving that signature in my database (as base30.) When I come back to the form and open that signature modal window again, the signature is missing. If I close the modal window and then open it again, then I can see the signature. It is like the modal window needs to run once.

function openSignature(strIn) { approverName = strIn; let strValue = $('#'+strIn).val(); if (strValue != '' ) { //$("#signature").jSignature('reset'); $("#signature").jSignature("setData", "data:" + strValue); //$("#signature").jSignature("setData", "data:" + strValue, "image/jsignature;base30"); //$("#signature").jSignature("importData", "data:" + strValue, "image/jsignature;base30"); //$sigdiv.jSignature("setData", strValue, "base30"); //$sigdiv.jSignature("setData", "data:" + strValue, "base30"); //$sigdiv.jSignature("setData", "data:" + datapair.join(",")); } else { $("#signature").jSignature('reset'); } $('#modalSignature').show(); $("#signature").resize(); } function saveSignature() { if ($("#signature").jSignature('isModified')) { //var datapair = $("#signature").jSignature("getData", "image/jsignature;base30"); var datapair = $("#signature").jSignature("getData", "base30"); //$('#'+approverName).val(datapair[1]); $('#'+approverName).val(datapair); $('#modalSignature').hide(); } else { if (confirm('The signature is unchanged?')) { $('#modalSignature').hide(); } } }

I would appreciate any thoughts!

brinley commented 2 years ago

Do you have effects when opening the modal? IIRC when initialising jSignature, there are checks to get the container height/width and might have race conditions if you have some sort of effect that affects the calculation of the container dimensions. You can experiment with some delay to initialisation of jSignature when opening the model to see if it helps

JamesInWA commented 2 years ago

I decided to treat every signature as a new signature so the issue was fixed that way.