Copy link to clipboard
Copied
Is it possible to add a Javascript so that a user cannot digitally sign unless all required fields are completed?
Copy link to clipboard
Copied
Only by hiding the signature field until all the required fields are filled in.
Copy link to clipboard
Copied
... or setting it to read-only until the required fields are filled.
Copy link to clipboard
Copied
Hi Joel
How could I set it to read-only until the required fields are filled?
Copy link to clipboard
Copied
Hi Try67
How could I go about hiding the signature field until all the required fields are completed?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
}
Copy link to clipboard
Copied
Hi,
you also need the script from the forum post I linked too, my script was just an addition to that script.
Regards
Malcolm
Copy link to clipboard
Copied
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
}
Copy link to clipboard
Copied
add a } at the end.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Hi Try67
Forgive me I'm not good with JavaScripts. Which section would you remove?
Copy link to clipboard
Copied
That depends on how you want it to work...
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I would like to validate all the required fields before the user can sign the document.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Then use this code as the custom calculation script of a (hidden) text field:
var allFilled = true;
for (var i=0; i<this.numFields; i++) {
var f= this.getField(this.getNthFieldName(i));
if (f.type!="button" && f.required && f.valueAsString==f.defaultValue) {
allFilled = false;
break;
}
}
this.getField("mySignatureField").display = (allFilled) ? display.visible : display.hidden;
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Hi Try67
I have now set the signature fields to the other required fields. How do I change the code to only execute when the signature field is not signed?
Copy link to clipboard
Copied
Add this condition around your current code:
if (this.getField("mySignatureField").value==null) {
// current code goes here
}
Copy link to clipboard
Copied
Thank you try67 BarlaeDC Bernd Alheit
Copy link to clipboard
Copied
Guys I'm sorry to bother you again.
I've had the form tested and when I select the confirm button its asking the user to go back and complete fields that aren't required and its missing fields that are required.
Is there any way I can fix this?