At the conference we learned how to add a signature field to an LF Form. We have implemented it and are loving it! Thank you so much for that. We have a form now that requires two signatures. How would we go about altering the signature code to allow for two signature fields?
Question
Question
How can I use the signature JavaScript from the BPM251 conference course demo with multiple signatures on the same form?
Answer
The signature code right now is set up to work with one signature, as you've encountered. The most straightforward way to do it is:
- Put all of the signature fields (including the custom HTML) into a collection, give the collection the sigCollection class.
- Go through all of the Custom HTML and change the ID attribute for each to instead be a class attribute (e.g., instead of "id="sigData" you'd change it to "class="sigData").
- Select the collection and click Duplicate.
Use this refactored signature code instead of the previous code. This code will allow you to modify the signatures independently of each other and will allow you to have more than one signature on the form.
function htmlEncode(value) { return $('<div/>').text(value).html(); } function htmlDecode(value) { return $('<div/>').html(value).text(); } $.getScript('https://dl.dropboxusercontent.com/u/14829216/jSignature.min.js', function () { $('.signature').jSignature(); }); /**When the page loads, check if the sig data (hidden) field has a value. If it has a value, decode it and put it in the image, and remove the signature pad and its buttons.**/ $(document).ready(function(){ $('.sigCollection').each(function () { var sigvalue = $(this).find('.sigdata textarea').text(); var sigrovalue = $(this).find('.sigdata .ro').text(); if (sigvalue != '' || sigrovalue != '') { var decoded = htmlDecode(sigvalue == '' ? sigrovalue : sigvalue); var $img = $('<img class=imported></img>'); $img.attr("src", decoded).appendTo($(this).find('.sigimage')); $(this).find('.sigGroup').remove(); //class added to the signature button and image custom HTML fields. $(this).find('.sigwarning').hide(); } }); $('.donebutton').click(function () { var section = $(this).closest('.sigCollection'); var sigdata = section.find('.signature').jSignature('getData'); section.find('.sigdata textarea').val(htmlEncode(sigdata)); var $img = $('<img class=imported></img>'); $img.attr("src", section.find('.signature').jSignature('getData')).appendTo(section.find('.sigimage')); section.find('.sigGroup').remove(); //class added to the signature button and image custom HTML fields. section.find('.sigwarning').hide(); }); $('.clearbutton').click(function () { var section = $(this).closest('.sigCollection'); section.find('.signature').jSignature('clear'); }); });
It's a good idea to use the instructions in the BPM251 zip file to place the jSignatures library in your Forms Server directory and then call it in the code, instead of the dropbox as shown above.
Eric, I implemented the code it works great for what we needed. I decided to do a little test though and set the repeat range for the Collection to 1-5. When I click the add link on the form, the section repeats, but the signature field does not show. It looks like the following:
What would I need to change so that would display correctly?
You need to call the .jSignature method on the newly created signature area. The code as written only calls this once when the form loads, so it doesn't account for those that are created after the form loads.
You'll want to:
- Detect the add button click.
- Find the closest .signature and call the .jSignature() method on it.
Replies
All I did on my implementation is make a copy of the scripts and rename them. Then I just copied the working signature section and changed the references to these scripts by adding a 2.
This seemed to work just fine.
This does not address the fundamental issues with the JavaScript on the CSS and JavaScript page. Without changing the code on the Script page (as well as changing some of the custom HTML fields) the code will consider both signature fields as the same field, which is not what you want.
What sort of issue might I have in production with doing it my way? I didn't find any issues in testing and uploading two different signatures using this method. Of course I needed to make a copy of all the css code and make sure they referenced other names too (#donebutton2, #signature2, etc)
Maybe I just needed that and not have this: (?)
$.getScript('http://10.2.5.12/forms/js/jsignature/jSignature2.min.js', function() { $('#signature2').jSignature(); });
If you're manually reproducing the code and remapping references, your method will work (although it's not necessary to create another copy of the jSignature library). Assuming you are using #signature1 and #signature2, the following should work for both signatures (without the need for a second $.getScript call):
$.getScript('http://10.2.5.12/forms/js/jsignature/jSignature2.min.js', function() { $('#signature2, #signature1').jSignature(); });
Ahh.. so I went too far in fixing it. I'll remember that for future use.
I did this all before the conference so originally I had a much more complex system. I didn't figure out the code to refresh the page for printing into laserfiche so I actually had sdk scripts that would export the SVG to a supported image file and stamp it back on as an image after it was placed into laserfiche running in workflow.
When performing an upgrade to forms, will the JavaScript files in the /Forms/js folder be deleted?
They were removed going from Forms 9.0.x to Forms 9.1, so I'd suggest backing up these files before major upgrades. It shouldn't be an issue for minor upgrades, though.
How would one go about changing the height of the signature field?
Pulled from Stackoverflow: (I'm at home now so I can't test)
You need to target canvas.jSignature
with your CSS.
CSS File
canvas.jSignature { height: 500px; }
It looks like you'll also need to change the height=""
attribute on the <canvas>
element as well.
I can add the "canvas.jSignature { height: 500px; }" to the CSS editor in forms, but the Canvas itself seems to be connected to the custom HTML field in Forms with the ID of signature. I'm not finding where to edit the Canvas itself.
jSignature automatically maximizes the canvas within the confines of its container div. So all you have to do is change the dimensions of the div.
You can find the plugin documentation here.
Eric,
I have been able to implement the single signature code and it works great - Thanks. Now we are trying to implement the multiple signature code and have been unable to get this to work. I am sure we are missing a step, so to explain the steps we have attempted I modified your instructions from BPM251. I will attach the .txt file. Following the attached steps everything looks good, except the signature block is not there.
Suggestions?
Thank you.
Cynthia Stewart
Is the getScript URL correct? The rest looks fine. If you replace it with this URL does it work? If that is the case, make sure you put the jSignature.min.js file in the correct location on your Forms Server machine and that you have the correct URL to it in your script. If you already implemented the single-signature version and it works, you can grab the URL from that .getScript method and use that.
Thanks for the quick response Eric. You were right it was the getScriptURL.
Thanks again.
You're welcome!
One other issue that I have run into with the multiple signatures (utilizing the same instructions I uploaded yesterday) is that the Done and Clear buttons do not work. Any suggestions?
The JavaScript is correct, so I'd check to ensure that the HTML for your buttons is using classes instead of identifiers.
I've attached a working copy of this process if you'd like to check it against yours (just change the file extension to xml instead of txt). Of course, you'll need to update the getScript URL for this process.
In regard to the Clear and Done buttons not functioning properly. We still have not spotted where we are off. Below are the steps and the custom HTML being utilized. Any assistance is appreciated.
- Collection created with class sigCollection
- Multi-line field called sig data in the Collection with class sigdata
- Custom HTML in the Collection with class SigGroup
<div class="signature"><br><div src="data:image/gif;base64,R0lGODlhtABJAOf/AAABAAACAAEEAAIFAQQHAgUIBAcJBQoJAAgLBwwLAAoMCA0MAA8OAwwPCxMQAA8RDRURABYSARITERMVBBQVExcXABgYAhYYFRkaBBwbABkaGB0cAR4dAhocGRsdGh8fBSIgAB0fHB4gHSAhHyQjBSckACIjISgmASQlIyooBSYnJSwpAC0qAC4rAS8rAikqKCssKjEuBTMvAC0uLDUwAjcyBS8xLzg0Bjs1ATIzMTw3Azk5BDQ2MzY3NTs7Bjw8Bzg5Nz49ADo7OUA/AkJABEJBBTw+O0RCBj5APUVECEdFAUFCQElGAkpIBERGQ0xKBk5LB09MCEdJRlJOAlNPA0pLSVRQBFZSBk1PTFdTB1hUCVtVAE9RTlxXAl5YBFJUUVRVU2BaBmFbCFZXVWJcCVZYVVlbWWZgAmhhBGliBVxeW15gXWxlCW1mC2BiX25nDHBoAXJqA2NlYnRrBmZnZXFu...Blv5BeoRgi3TAJAbUTDeAGxBAglBhnG8EP3LAKdtADscgqMXAGlQAMe3eLliEOmqBnKlIGu9A+qRiMlTiM2mAKdJAD8EYANJAGl6Bz0NgX5vAJTyAhBIAFs0A32vhTw4gNpCAHNgBvBlADbKAJxvCFm8QOqqAF4uEEq6A0kRePPbYR+zANoOBuVIYDbbAJn2Zn7RALYsAZO2EEoICKB4mQeKWQGWd0VJZsy+aPYxIPuMAGRpMDmeCHHemR1GS+ds5QdGuHL/JGb7DXJMBQB7H1ApBwfy8Jkz1kdsiQCWWAAh33cSGHI8fwB3+yEyZgCD9XN0LJHrhXDJYABpjXE0m3dE3HGtIwCKXYgn5waVRZlVwCE/ege7zHdm4Hd5UBaduzExJAB8jwIgmBlggJE/YgDJHABf/HExGgeaigDJVgW7yoBsKQIXrZmNuoEfvnCFigARZlAGCQC9jomJppcRshD72gCFXQAVUAC/C4maaZaUWSl6e5mgkZlBYREAA7" alt=""></div></div>
- Custom HTML in the Collection with class sigGroup
<p><input class="donebutton" value="Done" type="button"> <input class="clearbutton" value="Clear" type="button"></p>
- Custom HTML in the Collection
<div class="sigimage"></div>
- Custom HTML in the Collection
<p class="sigwarning">You must sign this form before submitting.</p>
That all looks good (the class in step 3 should be sigGroup, not SigGroup). If those fields are all within the signature collection, the remaining possibility is that there's a syntax error in your JavaScript. It'll be hard for me to troubleshoot this further without seeing the all the JavaScript you're including with the form or looking at the form itself.
Sorry for taking so much of your time on this. I really appreciate your assistance. I confirmed that it is set to sigGroup. I will attach the JavaScript. Is there anyway to export the form itself?
No problem! In this case, it's a very simple fix. The code I showed above was slightly incomplete and, if used by itself, needed to have a document.ready function.
To resolve the issue, add this first line to the code:
$(document).ready(function (){
and after the last line, add this:
});
Awesome! Thank you Eric - everything is working.
You're welcome!