Skip to main content
April 24, 2019
Question

Creating a conditional action with multiple required fields

  • April 24, 2019
  • 1 reply
  • 552 views

I'm new at this and I'm currently working on a document in Acrobat Pro DC where I want to have a portion of the document hidden until all of the required fields are filled with any value.

So far, I've only found resources on how to use a check box (or something similar like a button) to hide/show the additional portion of the document. This is what I'll end up doing as a last resort, but it's not ideal since the user will be able to toggle it on/off at any time, and my preference is for them to be able to do so only after all the fields are filled out.

My basic understand from using IF AND statements in Excel leads me to believe that should is a relatively simple script, but I haven't found any tutorials or examples of this scenario using JavaScript in Acrobat Pro DC. So any resources you can point me to would be appreciated!

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
April 24, 2019

The state of the"required" fields can be detected with a calculation script. Calculation scripts are run any time any field on the form is changed. I'm not sure what you mean by "required", so for the example code I'll use a list of field names.

Put this code in to a calculation script in any field on the form that is not already doing a calculation. You could even create a hidden field for this purpose.

var aFields = ["Field1", "Field2", "Field3", ...etc...];

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)

{

   ... Code for showing other part of form ...

}

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often