Skip to main content
brettt25731202
Inspiring
Jun 12, 2019 1:23 PM UTC
Answered

Signature completes and then required fields identified

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

bread_6630Correct answer
Participant
Jul 11, 2025 6:39 PM UTC

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

8 replies

JR Boulay
Community Expert
Community Expert
Aug 28, 2025 10:53 PM UTC

[MOVED TO THE ACROBAT PRO DISCUSSIONS]

Translate
Acrobate du PDF, InDesigner et Photoshopographe
bread_6630Correct answer
Participant
Jul 11, 2025 6:39 PM UTC

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;
}
}
Translate
Bernd Alheit
Community Expert
Community Expert
Jun 12, 2019 1:26 PM UTC

You must check the fields before signing the document.

Translate
brettt25731202
Inspiring
Jun 12, 2019 1:49 PM UTC

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.

Translate
Bernd Alheit
Community Expert
Community Expert
Jun 12, 2019 3:20 PM UTC

You can add the code to a form button.

Translate