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

Conditional hiding of dropdown field values based on previous dropdown field selection

Contributor ,
Sep 22, 2023 Sep 22, 2023

Eventually, this script will have to cover nearly 100 dropdown fields (one for every ship selectable).  The end-state is to minimize the required scrolling, disallow duplicate selections, and hopefully allow for first letter(s) input to jump to through the alphabetical listing.

Is there even a way to conditionally hide dropdown values based on previous selections?  I have been tinkering with this for a week now and am no closer to making it work.  Below is the code I've been attempting to implement and attached is my working test file.

My sincerest thanks in advance for your time and any and all assistance.

 

DROPDOWN 01 - replicated & modified for each successive dropdown.

var dropdown1 = this.getField("Drop01");
var dropdown2 = this.getField("Drop02");
var dropdown3 = this.getField("Drop03");
var dropdown3 = this.getField("Drop04");
dropdown1.setAction("Keystroke", function() {
var selectedValue1 = dropdown1.value;
if (selectedValue1 === "Reagan") {
dropdown2.setItems(["Enterprise", "Roosevelt", "Stennis"]);
} else if (selectedValue1 === "Enterprise") {
dropdown2.setItems(["Reagan", "Roosevelt", "Stennis"]);
} else if (selectedValue1 === "Roosevelt") {
dropdown2.setItems(["Reagan", "Enterprise", "Stennis"]);
} else if (selectedValue1 === "Stennis") {
dropdown2.setItems(["Reagan", "Enterprise", "Roosevelt"]);
} else {
dropdown2.setItems(["Reagan", "Enterprise", "Roosevelt", "Stennis"]);
}
});

 

TOPICS
How to , JavaScript , PDF , PDF forms
1.9K
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
2 ACCEPTED SOLUTIONS
Community Expert ,
Sep 22, 2023 Sep 22, 2023

Use this as Document level script:

function editList(){
  var num = parseInt(event.target.name.split(/[A-Za-z]+/)[1], 10);
  num++;
  var f = num < 10 ? "Ship" + "0" + num : "Ship" + num;
  var fname = this.getField(f);
  var cList = [" ", "Reagan", "Enterprise", "Roosevelt", "Stennis"];
  
  if (event.value === " ")
    fname.setItems(cList);
  else{
    var filteredList = [];
    for(var i=0; i<cList.length; i++){
      if (cList[i] !== event.value)
        filteredList.push(cList[i]);}
  fname.setItems(filteredList);}}

Call function from every field keystroke script:

if(event.willCommit){
 editList();}

View solution in original post

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 ,
Sep 23, 2023 Sep 23, 2023

If you use this as 'Validate' script, it will reject duplicate selection:

if(event.value !== " " && event.value !== ""){
for( var j=1; j<=4; j++){
var f2 = j < 10 ? "Ship" + "0" + j : "Ship" + j;
if(this.getField(f2).value == event.value){
event.rc = false;
break;}}}

Change 4 to the number of "Ship" fields you have.

View solution in original post

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 ,
Sep 22, 2023 Sep 22, 2023

Why are you using the setAction method for this? This just complicates things, as you need to apply the code as a string. Just apply the code directly to the field. Also, replace this:

var selectedValue1 = dropdown1.value;

With:

var selectedValue1 = event.value;

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
Contributor ,
Sep 22, 2023 Sep 22, 2023

Frankly, my forays into the FM (f*cking magic) of Arcobat scripting are the result of the bright idea fairy visiting the brass and my inability to quit or cry uncle -- which the brass clearly takes advantage of. Unfortunately, they refuse to execute on my advice to hire a subject matter expert to work the FM... despite being told and given evidence of my insane level of effort long before I ask for an assist in these forums. Last time, the response received was "you should've just gone to the forums to begin with" which resulted in an argument they should hire or contract someone who actually knows what they are doing... they've been told and shown the correspondence proving if it weren't for you, Nesa, Bebarth, Bernd, and ls_rbls having provided extreme assistance over the past 12+ months, they would not have been able to keep the promises they make when I'm not around to manage expectations.  As a CT/AT/FP knuckledragger throughout my military career you can guess my worldly experience is clearly not condusive to understanding the arcane intricacies of Acrobat scripting... and thus far, there has only been one item I've had to tell them was impossible based on a month of research and my refusal to post in the here.

All that being said, I truly appreciate the folks here who have made the magic happen and I have learned quite a bit in the process -- although clearly not enough as my example script above puts on public display. 😉

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 ,
Sep 22, 2023 Sep 22, 2023

I actually set up something similar to what you are asking for in one of my demo files. See the dropdowns in the attached PDF.  Select a meal and a second dropdown will appear with all of the same options as the first except the one selected. If that's what you were looking for, I can give you a detailed reply on how to tune it to your needs.

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 ,
Sep 22, 2023 Sep 22, 2023

Use this as Document level script:

function editList(){
  var num = parseInt(event.target.name.split(/[A-Za-z]+/)[1], 10);
  num++;
  var f = num < 10 ? "Ship" + "0" + num : "Ship" + num;
  var fname = this.getField(f);
  var cList = [" ", "Reagan", "Enterprise", "Roosevelt", "Stennis"];
  
  if (event.value === " ")
    fname.setItems(cList);
  else{
    var filteredList = [];
    for(var i=0; i<cList.length; i++){
      if (cList[i] !== event.value)
        filteredList.push(cList[i]);}
  fname.setItems(filteredList);}}

Call function from every field keystroke script:

if(event.willCommit){
 editList();}
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
Contributor ,
Sep 22, 2023 Sep 22, 2023

I am absolutely floored at how clean and elegant the solution you have provided. Please accept my admiration and sincerest appreciation.  Thank you! 

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
Contributor ,
Sep 22, 2023 Sep 22, 2023

Nesa, please accept my apologies for the following question. Is it possible to add something that prevents duplicate entries?  I've been tinkering in an attempt to ensure there can be no duplicate entries as well? There will eventually be 92 pulldown fields with the same selections -- aside from your script.  Is this possible with the script you've provided? 

Earlier in the week I was working a script that, unfortunately, removed the selection entirely from every follow-on dropdown after selected once... this wasn't acceptable to the brass as it wouldn't accomodate the accidental selection of a ship allowing the end-user to undo an incorrect selection and possibly add it back afterwards.

Again, my thanks, appreciation, and sincere hope you have a fantastic weekend. 🙂

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 ,
Sep 23, 2023 Sep 23, 2023

If you use this as 'Validate' script, it will reject duplicate selection:

if(event.value !== " " && event.value !== ""){
for( var j=1; j<=4; j++){
var f2 = j < 10 ? "Ship" + "0" + j : "Ship" + j;
if(this.getField(f2).value == event.value){
event.rc = false;
break;}}}

Change 4 to the number of "Ship" fields you have.

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
Contributor ,
Sep 23, 2023 Sep 23, 2023
LATEST

Thank you for your time and your patience. 🙂

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