Skip to main content
Known Participant
April 18, 2019
Question

Is it possible to add a Javascript so that a user cannot digitally sign unless all required fields are completed?

  • April 18, 2019
  • 8 replies
  • 2966 views

Is it possible to add a Javascript so that a user cannot digitally sign unless all required fields are completed?

This topic has been closed for replies.

8 replies

CiaranMHRAuthor
Known Participant
May 7, 2019

Hi Try67 and BarlaeDC

I'm noticing now when the user enters their signature it becomes invisible and I can't do see it.

Is there a way to fix this?

CiaranMHRAuthor
Known Participant
May 7, 2019
try67
Community Expert
Community Expert
May 7, 2019

You need to set the signature fields to lock all the other fields. It's also possible to change the code above to only execute when the signature field is not signed.

CiaranMHRAuthor
Known Participant
April 25, 2019

I would like to validate all the required fields before the user can sign the document.

BarlaeDC
Community Expert
Community Expert
April 25, 2019

Hi,

Just removing unneeded code from the posts above, this goes through all fields in the document and only checks the fields that are required.

var emptyFields = [];

for (var i=0; i<this.numFields; i++) {

     var f= this.getField(this.getNthFieldName(i));

     if (f.type!="button" && f.required ) {

          if ((f.type=="text" && f.valueAsString=="") || (f.type=="checkbox" && f.value=="Off")) emptyFields.push(f.name);

     }

}

if (emptyFields.length>0) {

     app.alert("Error! You must fill in the following fields:\n" + emptyFields.join("\n"));

     this.getField("mySignatureField").display = display.hidden

}

else

{

     this.getField("mySignatureField").display = display.visible;

}

As you have a dialog being shown it would be best to add this to something the user triggers, such as a "Check Form" button.

Regards

Malcolm

CiaranMHRAuthor
Known Participant
April 24, 2019

Hi Try67

In the signature field I have:

a section of the file being locked after approval

an error message to advise the user of any required fields that are not completed.

and the script in question.

I just want:

a section of the file being locked after approval

the user to be unable to add their digital signature until all required fields are completed?

try67
Community Expert
Community Expert
April 24, 2019

You can't do that from the Signed event, as at that point the field is already signed. But that was not really my question. I asked whether you want to validate all the required fields in the file before being able to sign the field, or just the fields from a list.

CiaranMHRAuthor
Known Participant
April 24, 2019

Hi Try67

Forgive me I'm not good with JavaScripts. Which section would you remove?

try67
Community Expert
Community Expert
April 24, 2019

That depends on how you want it to work...

CiaranMHRAuthor
Known Participant
April 24, 2019

Hi Malcolm

I followed the instructions on the link. I created a hidden field on the form and added the below script but its bringing up an error message?

var emptyFields = [];

for (var i=0; i<this.numFields; i++) {

     var f= this.getField(this.getNthFieldName(i));

     if (f.type!="button" && f.required ) {

          if ((f.type=="text" && f.valueAsString=="") || (f.type=="checkbox" && f.value=="Off")) emptyFields.push(f.name);
     }
}
if (emptyFields.length>0) {
     app.alert("Error! You must fill in the following fields:\n" + emptyFields.join("\n"));
}
f.valueAsString==""
0=="";
var aFields = ["Start Date", "Name", "Status", "Job Title","Person Type","HR Manager","Manager","Working Hours","start","Finish","Pro Day","Pro Mont","Note Day","Note Mont","Evac Site","Roster","Softworks Dept","Currency","Salary","Sal Basis","Sal Year","Per","Per F","Company Car","Car Allowance","Fuel Card","Fuel Allowance","PlanType","LocalBonus","Sub Plan","Annual Target","Target Amount","Charged Segment","Healthcare","Local Healthcare","Life Insurance","Overtime","Employee","Employer","Organisation","BU Overide","Department Headcount","Location","Payroll1","Assign Category","Job Code","Apprenticeship","Location120","Account","Cost Centre","Product Line","Interco","Future","dropdown1","dropdown2","dropdown3","Safety","TTMS Module","Non-Majority","Badge/Fob","Internet","Laptop",];

var bAllFilled = true;

for(var i=0;i<aFields.length;i++)

{
    var oFld = this.getField(aFields);
     if(oFld.value == oFld.defaultValue)
     {
          bAllFilled = false;
          break;
      }
}
if(bAllFilled)
{
if(bAllFilled)
{
     this.getField("mySignatureField").display = display.visible;
}
else
{

     this.getField("mySignatureField").display = display.hidden
}

Bernd Alheit
Community Expert
Community Expert
April 24, 2019

add a } at the end.

try67
Community Expert
Community Expert
April 24, 2019

There are other issues with the code. Namely, it's an amalgam of two ways of doing it, one that checks all requires fields in the file and one that checks specific fields, defined in a list. It doesn't make sense to use both.

CiaranMHRAuthor
Known Participant
April 24, 2019

Hi Malcolm

Thanks for getting back to me. I changed the name of the digital signature field to mySignatureField and added the below script but its not working. Is there something else I need to added to the script?

if(bAllFilled)

{

     this.getField("mySignatureField").display = display.visible;

}

else

{

     this.getField("mySignatureField").display = display.hidden

}

BarlaeDC
Community Expert
Community Expert
April 24, 2019

Hi,

you also need the script from the forum post I linked too, my script was just an addition to that script.

Regards

Malcolm

BarlaeDC
Community Expert
Community Expert
April 24, 2019

Hi,

Could you not use something like this - Creating a conditional action with multiple required fields

If you set your signature field to hidden or readonly in the UI so when the user opens the document there is no signature field.

The only bit you might want to add to be save is an 'else' to make sure your signature field gets hidden again if the user changes any fields so they are not filled in.

// code shown for hiding and showing a signature field called "mySignatureField".

if(bAllFilled)

{

     this.getField("mySignatureField").display = display.visible;

}

else

{

this.getField("mySignatureField").display = display.hidden;

}

Regards

Malcolm

try67
Community Expert
Community Expert
April 18, 2019

Only by hiding the signature field until all the required fields are filled in.

Joel Geraci
Community Expert
Community Expert
April 18, 2019

... or setting it to read-only until the required fields are filled.

CiaranMHRAuthor
Known Participant
April 24, 2019

Hi Joel

How could I set it to read-only until the required fields are filled?