Skip to main content
brettt25731202
Inspiring
June 12, 2019
Answered

Signature completes and then required fields identified

  • June 12, 2019
  • 3 replies
  • 1051 views

My form has required fields and I want to identify blanks before applying the electronic signature and then emailing.

I need the JS to work in the following order

1. Check for blank required fields

2. If complete apply signature and then save the file

3. Prompt emailing the document

 

I am using the following Java Script in the Digital Signature Properties under the Signed tab.

The end user will use DC reader.

 

Thanks for the help.

 

var requiredFields = new Array();

 

 

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

 

 

{

 

 

var fName = this.getNthFieldName(i);

 

 

var f = this.getField(fName);

 

 

if (f.type!="button" && this.getField(fName).required && (this.getField(fName).value == null || this.getField(fName).value == ''))

 

 

{

 

 

requiredFields[requiredFields.length] = fName;}}

 

 

var error = "Please complete the following fields: \n\n";

 

 

for (j=0; j < requiredFields.length; j++)

 

 

{

 

 

if (requiredFields.value == null)

 

 

{

 

 

error = error + requiredFields + '\n';

 

 

var f2 = this.getField(requiredFields);

 

 

f2.setFocus();

 

 

}

 

 

 

 

 

}

 

 

 

 

 

if(requiredFields.length > 0)

 

 

app.alert(error);

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

 

 

{

 

 

    var cFldName = this.getNthFieldName(i);

 

 

    var oFld = this.getField(cFldName);

 

 

    if(oFld.required && (oFld.defaultValue == oFld.value))

 

 

    {

 

 

        app.alert("Field " + cFldName + " is empty");

 

 

 

 

    }

 

 

}

 

 

 

 

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

 

 

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

 

 

if (f.type!= "signature") //

 

 

{

 

 

f.readonly = true ;

 

 

}

 

 

}

 

 

 

 

this.mailDoc({cTo:"", cSubject: "Purchase Request",  cMsg: "Please review and electronically Sign Document"});

Correct answer bread_6630

I know this thread is old but put this in the signature field as a "mouse down" action:

 

if (!validateRequiredFields(this)){
    event.rc = false; //prevent signing
    this.getField("BonaFideNeedSig").readonly = true; //using readonly as a backup
    }else{
 
//If validation passes, allow signing to proceed
    event.rc = true;
    this.getField("BonaFideNeedSig").readonly = false; //using readonly as a backup
}
 
function validateRequiredFields(doc) {
var emptyFields = [];
for (var i=0; i<doc.numFields; i++) {
var f = doc.getField(doc.getNthFieldName(i));
if (f !=null && f.type !="button" && f.required && f.valueAsString==f.defaultValue) {
emptyFields.push(f.name);
}
}
 
if (emptyFields.length>0) {
app.alert("You must fill in the following required fields before you can sign here:\n\n" + emptyFields.join("\n"));
return false;
}
    else{
            app.alert("All required fields are filled and your form is ready for signature.",4);
return true;
}
}

3 replies

JR Boulay
Community Expert
Community Expert
August 28, 2025

[MOVED TO THE ACROBAT PRO DISCUSSIONS]

Acrobate du PDF, InDesigner et Photoshopographe
bread_6630Correct answer
Participant
July 11, 2025

I know this thread is old but put this in the signature field as a "mouse down" action:

 

if (!validateRequiredFields(this)){
    event.rc = false; //prevent signing
    this.getField("BonaFideNeedSig").readonly = true; //using readonly as a backup
    }else{
 
//If validation passes, allow signing to proceed
    event.rc = true;
    this.getField("BonaFideNeedSig").readonly = false; //using readonly as a backup
}
 
function validateRequiredFields(doc) {
var emptyFields = [];
for (var i=0; i<doc.numFields; i++) {
var f = doc.getField(doc.getNthFieldName(i));
if (f !=null && f.type !="button" && f.required && f.valueAsString==f.defaultValue) {
emptyFields.push(f.name);
}
}
 
if (emptyFields.length>0) {
app.alert("You must fill in the following required fields before you can sign here:\n\n" + emptyFields.join("\n"));
return false;
}
    else{
            app.alert("All required fields are filled and your form is ready for signature.",4);
return true;
}
}
Bernd Alheit
Community Expert
Community Expert
June 12, 2019

You must check the fields before signing the document.

brettt25731202
Inspiring
June 12, 2019

Sorry, but I need a little more help, I am fairly new to Java script.  How do I get the fields checked prior to signature?  Whats the forcing function?  Otherwise people will submit incomplete documents.

Bernd Alheit
Community Expert
Community Expert
June 12, 2019

You can add the code to a form button.