Skip to main content
Participant
April 17, 2024
Question

How to make a field required base on any specific choices from dropdown list in PDF

  • April 17, 2024
  • 2 replies
  • 948 views

I have a signature field, named "CredSig1", that I would like to make required based on dropdown selections at "cred" in which has a list of credentialing roles (i.e. Audiologist, Registered Nurse, Medical Assistant, etc.).

 

I have set a validation script below that works for "Audiologist", however, I cannot get others to work simultaneously: 

 

var target = this.getField("CredSig1");
target.required = event.value == "Audiologist" ? true : false;

 

How can i script it to identify multiple values if one is selected to make a field required?

 

FYI, there is only one selection in this field. I would like Audiologist, Registered Nurse, Physicians, or Nurse Practitioner, if selected to make "CredSig1" required. 

 

Thank you in advance.

This topic has been closed for replies.

2 replies

Nesa Nurani
Community Expert
Community Expert
April 18, 2024

You can do it like this:

var target = this.getField("CredSig1");
var requiredRoles = ["Audiologist", "Registered Nurse", "Physician", "Nurse Practitioner"];

target.required = requiredRoles.indexOf(event.value) !== -1;
Thom Parker
Community Expert
Community Expert
April 17, 2024

Handling  multiple values requires a "if" statement:

Read this:

https://www.pdfscripting.com/public/How-to-write-an-If-statement.cfm

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
April 17, 2024

where do I start the if statement for this particular set?

Thom Parker
Community Expert
Community Expert
April 17, 2024

You haven't outlined the specific required conditions, but here's a script that makes the target required if any of several values are selected.  If the requirements are different, then the logic in the "if" will need to be modified.

 

if((event.value == "Audiologist") || (event.value == "Registered Nurse") || etc.)
    target.required = true;
else
    target.required = false;

 

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