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

Display/Hide multiple fields based on dropdown selection

New Here ,
Feb 25, 2020 Feb 25, 2020

Copy link to clipboard

Copied

I'm using Acrobat Pro DC and I'm somewhere between Novice and Amateur user level with JS. 🙂

 

I'm creating a form with a dropdown list that I would like to trigger whether or not specific other fields are displayed or hidden to the user based on the choice. I've found similar situations in other cases, but nothing that quite fits what I'm trying.

 

I have used the following successfully, but I'm trying to find a faster way to reference the common fields that will be hidden or displayed based on the selection....especially as I'm looking at adding more as the form develops. I'm running this as a custom validation script on the dropdown.

 

This worked:
if (event.value == "Reclassify a Filled Position") {
this.getField("EmplName").display = display.visible;
this.getField("EmployeeName").display = display.visible;
this.getField("EmplID").display = display.visible;
this.getField("EmplIDNum").display = display.visible;
this.getField("EndDate").display = display.hidden;
this.getField("EndDt").display = display.hidden;
}
else if (event.value == "Special Pay Increase - Temporary") {
selectedSPI.display = display.visible;
this.getField("EmplName").display = display.visible;
this.getField("EmployeeName").display = display.visible;
this.getField("EmplID").display = display.visible;
this.getField("EmplIDNum").display = display.visible;
this.getField("EndDate").display = display.visible;
this.getField("EndDt").display = display.visible;
}

 

This didn't work the way I wanted:

var selectSPI = this.getField("SPIType");
var selectFilled = this.getField("EmplName" && "EmployeeName" && "EmplID"&&"EmplIDNum");
var selectVacant = this.getField("ReqHireRng" && "HireRng");
var selectTemp = this.getField("EndDate" && "EndDt");

 

if (event.value == "Reclassify a Filled Position") {
selectFilled.display = display.visible;
selectSPI.display = display.hidden;
selectVacant.display = display.hidden;
selectTemp.display = display.hidden;
}
else if (event.value == "Special Pay Increase - Permanent") {
selectFilled.display = display.visible;
selectSPI.display = display.visible;
selectVacant.display = display.hidden;
selectTemp.display = display.hidden;

(etc)

 

So really, I guess I'm trying to find out if here's a way to reference numerous fields in a variable and how to do it. I found something related to using switch cases, but I'm not sure how I'd implement it in this scenario.

 

Thanks!

TOPICS
Acrobat SDK and JavaScript

Views

1.2K

Translate

Translate

Report

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 ,
Feb 25, 2020 Feb 25, 2020

Copy link to clipboard

Copied

LATEST

You can put field names in an array and use a loop over the array.

Votes

Translate

Translate

Report

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