Skip to main content
Participating Frequently
September 24, 2025
Question

Create field showing all required fields have been populated

  • September 24, 2025
  • 3 replies
  • 1348 views

Hi, I have a form with a number of required fields.  The form isn't submitted online, just emailed to me.

I would like to add a field at the top of the page "Form Complete" that would turn green or show a checkmark when all required fields have been entered.  I have marked each field as being required or not in the properties of each one.  I believe that I need a java script to loop through the fields and validate that required fields are populated.  Can anyone help me with that? Thank you!

3 replies

Participant
September 26, 2025

That’s a smart idea a quick visual check saves time. It’s like getting a mid taper fade, clean and polished so everything looks just right at a glance.

Thom Parker
Community Expert
Community Expert
September 24, 2025

I'd do this one a little differently.  Use the default value as an indicator.  

Use a text field for this calculation script. 

Note that the script skips buttons, which cannot be required, and signature fields, which need to be validated differently. 

 

var nComplete=0, nRequired = 0;
for(var i = 0; i < this.numFields; i++)
{
    var oFld=this.getField(this.getNthFieldName(i));
    if((oFld.type != "button") && (oFld.type != "signature")) {
        if(oFld.required){
            nRequired ++;
            if(oFld.defaultValue != oFld.value) nComplete++;
        }
     }
}

if(nComplete == nRequired){
    event.value = "All Required Fields Complete (" + nRequired + " required)";
    event.target.fillColor = color.green;
}
else{
    event.value = "Missing " + (nRequired-nComplete).toString + " Required Fields out of " + nRequired;
    event.target.fillColor = color.red;
}

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
PDF Automation Station
Community Expert
Community Expert
September 24, 2025

This line:

if(oFld.defaultValue != oFld.value) nComplete++;

will return a false positive if the field has a default value other than null and the field is manually cleared.

Thom Parker
Community Expert
Community Expert
September 25, 2025

Hmm, then the values need an explicit conversion to keep them in the same context. 

 

I've added a simple conversion function to the code. 

// Convert null, 0, and blanks to an empty string
function NullConvert(cIn){return (Number(cIn)==0?"":cIn);}

var nComplete=0, nRequired = 0;
for(var i = 0; i < this.numFields; i++)
{
    var oFld=this.getField(this.getNthFieldName(i));
    if((oFld.type != "button") && (oFld.type != "signature")) {
        if(oFld.required){
            nRequired ++;
            if(NullConvert(oFld.defaultValue) != NullConvert(oFld.value)) nComplete++;
        }
     }
}

if(nComplete == nRequired){
    event.value = "All Required Fields Complete (" + nRequired + " required)";
    event.target.fillColor = color.green;
}
else{
    event.value = "Missing " + (nRequired-nComplete).toString() + " Required Fields out of " + nRequired;
    event.target.fillColor = color.red;
}

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
PDF Automation Station
Community Expert
Community Expert
September 24, 2025

Enter the following script as a custom calculation in the text field that you want to change color if all required fields are completed and change the 5 in the script to the number of required fields:

var count=0;
for(var i = 0; i < this.numFields; i++)
{
var fieldName = this.getNthFieldName(i);
var oFld=this.getField(fieldName);
if(oFld==null){continue}
if(oFld.required==true && oFld.value!="")
{count++}
}

count==5?event.target.fillColor=color.green:event.target.fillColor=color.transparent;