You are viewing limited content. For full access, please sign in.

Question

Question

How can I use the signature JavaScript from the BPM251 conference course demo with multiple signatures on the same form?

asked on February 28, 2014 Show version history

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?

0 0

Answer

SELECTED ANSWER
replied on February 28, 2014 Show version history

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:

 

  1. Put all of the signature fields (including the custom HTML) into a collection, give the collection the sigCollection class.
  2. 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").
  3. 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.

1 0
replied on June 12, 2014

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?

0 0
replied on June 13, 2014

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:

  1. Detect the add button click.
  2. Find the closest .signature and call the .jSignature() method on it.

 

 

0 0

Replies

replied on February 28, 2014 Show version history

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. 

 

1 0
replied on February 28, 2014

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.

0 0
replied on February 28, 2014

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();
  });

 

0 0
replied on February 28, 2014 Show version history

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();
 });

 

0 0
replied on February 28, 2014 Show version history

Ahh.. so I went too far in fixing it. I'll remember that for future use. laugh

 

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. 

0 0
replied on March 3, 2014

When performing an upgrade to forms, will the JavaScript files in the /Forms/js folder be deleted?

0 0
replied on March 3, 2014

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.

0 0
replied on February 28, 2014

How would one go about changing the height of the signature field?

0 0
replied on February 28, 2014 Show version history

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.

0 0
replied on March 3, 2014

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.

0 0
replied on March 3, 2014

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.

0 0
replied on March 3, 2014

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

 

0 0
replied on March 3, 2014 Show version history

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.

0 0
replied on March 3, 2014

Thanks for the quick response Eric. You were right it was the getScriptURL.

Thanks again.

0 0
replied on March 3, 2014

You're welcome!

0 0
replied on March 4, 2014

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?

0 0
replied on March 4, 2014

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.

0 0
replied on March 4, 2014

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.

 

  1. Collection created with class sigCollection
  2. Multi-line field called sig data in the Collection with class sigdata
  3. 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>

 

  1. Custom HTML in the Collection with class sigGroup

<p><input class="donebutton" value="Done" type="button"> <input class="clearbutton" value="Clear" type="button"></p>

 

  1. Custom HTML in the Collection

<div class="sigimage"></div>

 

  1. Custom HTML in the Collection

       <p class="sigwarning">You must sign this form before submitting.</p>

 

 

0 0
replied on March 5, 2014

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.

0 0
replied on March 5, 2014

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?

multiple.txt (1.66 KB)
0 0
replied on March 5, 2014

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:

});

 

0 0
replied on March 5, 2014

Awesome! Thank you Eric - everything is working.

0 0
replied on March 5, 2014

You're welcome!

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.