Copy link to clipboard
Copied
I am creating a PDF Form in Acrobat Pro DC. I have a list of over 40 items that I want in a drop down list that, when chosen, causes specific fields to appear or disappear. I am already using the code shown below, but the validation section of the drop down properties states that my validation code is too long and cuts me off at just over 1100 lines. Here are the questions that I can't find an answer to:
Is there a better way to: 1. create the drop down or 2. create the validation or 3. use a better form field option so that I can have this many items but still have it work in the file? Everything must be part of the PDF file itself with no outside data source. Maybe I'm just dreaming.
Here is what I've been using and it works great, but takes up too many lines of code once all 40 items are entered.
if (event.value == "Judge") {
this.getField("Murray").display = display.hidden;
this.getField("Hunn").display = display.hidden;
........ // (Remainder of items)
}
else if (event.value == "Murray") {
this.getField("Murray").display = display.visible;
this.getField("Hunn").display = display.hidden;
........ // (Remainder of items)
}
else (event.value == "Other") {
this.getField("Murray").display = display.hidden;
this.getField("Hunn").display = display.hidden;
........ // (Remainder of items)
}
Thoughts?
Todd
Copy link to clipboard
Copied
For long code use an external JavaScript editor.
As validation you can use this:
.... set all fields as hidden ....
if (this.getField(event.value)) this.getField(event.value).display = display.visible;
Copy link to clipboard
Copied
I have already opened with an if statement:
if (event.value == "Judge")
Does your suggested line replace my if statement? If so, how do I reference the field name in the script? Also how would I then set the fields to hidden if I am not referencing the field name?
I'm just not making the connection to how your suggested script figures into what I have done.
Copy link to clipboard
Copied
If you use hierachical naming for the fields you want to show/hide, you can hide them all with a single statement and show the one you want with a single statement. For example, if the fields were named: G1.Murray, G1.Hunn, etc., the code could be simplified to just:
// Hide all of the fields
getField("G1").display = display.hidden;
// Display the field corresponding to the selection
getField("G1." + event.value).display = display.visible;
Copy link to clipboard
Copied
Ok, so the hide function works fine, but I have labeled the fields per your suggestion and then used your display line and they don't display. This is what I'm showing now.
getField("G1").display = display.hidden;
getField("G1." + Murray).display = display.visible;
getField("G1." + Kress).display = display.visible;
getField("G1." + Hunn).display = display.visible;
getField("G1." + Laggis).display = display.visible;
getField("G1." + Hooste).display = display.visible;
getField("G1." + Smith).display = display.visible;
getField("G1." + Carnaroli).display = display.visible;
getField("G1." + Naftz).display = display.visible;
getField("G1." + Garbett).display = display.visible;
Copy link to clipboard
Copied
You'd have to do this:
getField("G1." + "Murray").display = display.visible;
or:
getField("G1.Murray").display = display.visible;
Copy link to clipboard
Copied
Ok so they now all show up at the same time, but they no longer hide. They also will not disappear after a new choice is made, so all the field options are overlapping. I am expecting the form users to pick wrong on occasion. Should there be an if-then statement?
getField("J1").display = display.hidden;
getField("J1.Murray").display = display.visible;
getField("J1.Kress").display = display.visible;
getField("J1.Hunn").display = display.visible;
getField("J1.Laggis").display = display.visible;
getField("J1.Hooste").display = display.visible;
getField("J1.Smith").display = display.visible;
getField("J1.Carnaroli").display = display.visible;
getField("J1.Naftz").display = display.visible;
getField("J1.Garbett").display = display.visible;
Copy link to clipboard
Copied
Use only this one line:
this.getField("J1." + event.value).display = display.visible;
Copy link to clipboard
Copied
It still isn't working. The field names match what is listed below. Here is the entire validation code that I have, but the fields now won't hide and they all show at the same time and overlap. I don't know what the problem is.
// Hide all of the fields
this.getField("J1.").display = display.hidden;
// Display the field corresponding to the selection
this.getField("J1." + "Murray").display = display.visible;
this.getField("J1." + "Kress").display = display.visible;
this.getField("J1." + "Hunn").display = display.visible;
this.getField("J1." + "Laggis").display = display.visible;
this.getField("J1." + "Hooste").display = display.visible;
this.getField("J1." + "Smith").display = display.visible;
this.getField("J1." + "Carnaroli").display = display.visible;
this.getField("J1." + "Naftz").display = display.visible;
this.getField("J1." + "Garbett").display = display.visible;
Copy link to clipboard
Copied
Your code is setting all of the J1 fields to hidden, and then immediately sets 9 of the J1 fields to visible. It's not clear why you're doing this, as opposed to just setting the field that corresponds to the selection to visible.
Copy link to clipboard
Copied
Use this:
this.getField("J1." + event.value).display = display.visible;
When "Kress" was selected it will display the field "J1.Kress".
Find more inspiration, events, and resources on the new Adobe Community
Explore Now