Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Community Beginner ,
Apr 17, 2024 Apr 17, 2024

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.

TOPICS
Create PDFs , How to , PDF , PDF forms
843
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 17, 2024 Apr 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 17, 2024 Apr 17, 2024

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 17, 2024 Apr 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 18, 2024 Apr 18, 2024

Thank you I finally got it using your script. I added the var target = ("CredSig1") to make it align. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 18, 2024 Apr 18, 2024
LATEST

Correct, I only included the "if" part of the code since that's the piece that was missing. 

There's actually several ways this could be done, including a modification to your original code.

And Nesa provided a novel and clever method.

 

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 17, 2024 Apr 17, 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;
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines