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

Nested If Then with Multiple Conditions - Showing Last Option Chosen

Explorer ,
Sep 12, 2020 Sep 12, 2020

Copy link to clipboard

Copied

Here's a stumper for you.

 

I have been trying to create a form which can have certain fields resize to handle additional input. There are 3 different fields that can be resized by the user and then the form spawns or deletes pages to show the fields at the sizes the people have chosen. In all, there are 27 different field combinations. In order to accomodate this, I have been trying to use nested if statements. The options are simply "Small Size", "Medium Size", and "Large Size" for each field. The problem I'm running into is that the beginning option when the form loads is "Small Size" and the page shows the appropriate size field. When I choose "Medium" though, "Small" stays. Then when I choose "Large",  "Medium" shows up. Then when I choose "Small" or "Medium", "Large" will show all with the proper accompanying pages. The form is showing the fields and pages of the last option that was chosen when you click the next option. Gosh this sounds insane and I hope it's not too confusing. I have other less complicated dropdowns to show or hide fields/pages and this is the only one that won't work. 

 

Here is the partial nested if-thens that I used.

 

var Drop1 = this.getField("Drop.01").value;

var Drop2 = this.getField("Drop.02").value;

var Drop3 = this.getField("Drop.03").value

 

if( event.value == "Drop.01" ) {

this.getField("1K.").display = display.visible; } \\ this seemed unnecessary before, so I took it out once. No Difference.

 

else if( Drop1 == "Small Size" ) {

   if( Drop2 == "Small Size" && Drop3 == "Small Size" ) {

   var expTplt1 = getTemplate("1K1-2");

   expTplt1.spawn(numPages,false,false);

   var expTplt2 = getTemplate("1K1-3");

   expTplt2.spawn(numPages,false,false);

   var expTplt3 = getTemplate("1K1-4");

   expTplt3.spawn(numPages,false,false);

   this.pageNum = 1;}

   

   else if( Drop2 == "Medium Size" && Drop3 == "Small Size" ) {

   var expTplt1 = getTemplate("1K2-2");

   expTplt1.spawn(numPages,false,false); \\...

   

\\ ... additional options

}

 

else if( Drop1 == "Medium Size" ) {

   if( Drop2 == "Small Size" && Drop3 == "Small Size" ) {

   var expTplt1 = getTemplate("1K4-2");

   expTplt1.spawn(numPages,false,false);

   var expTplt2 = getTemplate("1K4-3");

   expTplt2.spawn(numPages,false,false);

   var expTplt3 = getTemplate("1K4-4");

   expTplt3.spawn(numPages,false,false);

   this.pageNum = 1;}

 

\\ ... additional options

}

 

else if( Drop1 == "Large Size" ) {

   if( Drop2 == "Small Size" && Drop3 == "Small Size" ) {

   var expTplt1 = getTemplate("1K7-2");

   expTplt1.spawn(numPages,false,false);

   var expTplt2 = getTemplate("1K7-3");

   expTplt2.spawn(numPages,false,false);

   var expTplt3 = getTemplate("1K7-4");

   expTplt3.spawn(numPages,false,false);

   var expTplt4 = getTemplate("1K7-5");

   expTplt4.spawn(numPages,false,false);

   this.pageNum = 1;}

 

\\ ... additional options

}

 

else { this.getField("1K.").display = display.visible; }

 

Hopefully you get the idea. There's probably a way easier way to do this, but I can't think of what it is at this point. I've been working on this for several days now. Help please!!! 

TOPICS
Acrobat SDK and JavaScript

Views

1.1K

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

correct answers 1 Correct answer

Explorer , Sep 16, 2020 Sep 16, 2020

So I figured it out and I will place a sample below. My problem was that I made the incorrect assumption that I could only have each event.value option once in the code (so I could only use the options of small, medium and large once each). After I figured that was wrong, all I had to do was place the other conditions. Hope that makes sense. There is probably a more efficient way to do this, but I could get this one to work, so I'm happy.

 

if (event.value == "Drop.01") { 

this.getField("1K.").disp

...

Votes

Translate

Translate
Community Expert ,
Sep 12, 2020 Sep 12, 2020

Copy link to clipboard

Copied

Where does you use the script?

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
Explorer ,
Sep 12, 2020 Sep 12, 2020

Copy link to clipboard

Copied

I'm not 100% sure what you mean, but i think you mean that you want to know which property field I am using... I hope.

 

As with my other javascript fields, I am using the "validate" dropdown property and NOT the "calculate" property.

 

Does that answer your question?

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
Community Expert ,
Sep 13, 2020 Sep 13, 2020

Copy link to clipboard

Copied

At validation you will get the value of the dropdown with:

event.value

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
Explorer ,
Sep 13, 2020 Sep 13, 2020

Copy link to clipboard

Copied

I know event.value is what you're supposed to use, but how do you mesh an event.value with the code that is spawning pages? This is not a numerical calculation so i couldn't find a way to use event.value. Can you give an example?

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
Community Expert ,
Sep 13, 2020 Sep 13, 2020

Copy link to clipboard

Copied

That has nothing to do with it. event.value can be a number, or a string, etc. But you must use it in a Validation script to get the field's new value.

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
Community Expert ,
Sep 13, 2020 Sep 13, 2020

Copy link to clipboard

Copied

E.g.

if (event.value == "Small Size") {

...

}

 

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
Community Expert ,
Sep 13, 2020 Sep 13, 2020

Copy link to clipboard

Copied

Remove the period after "==" ...

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
Explorer ,
Sep 14, 2020 Sep 14, 2020

Copy link to clipboard

Copied

I know that using event.value works in the case of one condition, but how would I apply event.value to a nested if statement with 3 conditions that have to be checked each time? I can't see how to make the variable an event.value and have it check the conditions each time.

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
Community Expert ,
Sep 14, 2020 Sep 14, 2020

Copy link to clipboard

Copied

At the first dropdown list replace

 var Drop1 = this.getField("Drop.01").value;

with

 var Drop1 = event.value;

 

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
Explorer ,
Sep 14, 2020 Sep 14, 2020

Copy link to clipboard

Copied

How does the variable know which field to find it's event.value in? var Drop1 needs to check dropdown field "Drop.01" for it's value each time to see if the value has changed. I tried doing all three var as you suggested and it didn't work. It actually deleted the visible pages completely.

 

var Drop1 = event.value;

var Drop2 = event.value;

var Drop3 = event.value

 

I also tried the following and it, while it did better that the one above, still had the same problem I started with.

 

var Drop1 = (event.value = this.getField("Drop.01").value);

var Drop2 = (event.value = this.getField("Drop.02").value);

var Drop3 = (event.value = this.getField("Drop.03").value)

 

The following worked (this was my original one) and it didn't use the var, but it only allows me to use 3 of the page combinations and not all 27. Maybe you can see something different that I can use.

 

if (event.value == "Drop.01") {

this.getField("1K.").display = display.visible;

}

 

else if (event.value == "Small Size") {

this.getField("Drop.01").value == "Small Size" && this.getField("Drop.02").value == "Small Size" && this.getField("Drop.03").value == "Small Size"

var expTplt1 = getTemplate("1K1-2");

expTplt1.spawn(numPages,false,false);

var expTplt2 = getTemplate("1K1-3");

expTplt2.spawn(numPages,false,false);

var expTplt3 = getTemplate("1K1-4");

expTplt3.spawn(numPages,false,false);

this.pageNum = 1; }

 

else if (event.value == "Medium Size") {

this.getField("Drop.01").value == "Medium Size" && this.getField("Drop.02").value == "Small Size" && this.getField("Drop.03").value == "Small Size"

var expTplt1 = getTemplate("1K4-2");

expTplt1.spawn(numPages,false,false);

var expTplt2 = getTemplate("1K4-3");

expTplt2.spawn(numPages,false,false);

var expTplt3 = getTemplate("1K4-4");

expTplt3.spawn(numPages,false,false);

this.pageNum = 1; }

 

else if (event.value == "Large Size") {

this.getField("Drop.01").value == "Large Size" && this.getField("Drop.02").value == "Small Size" && this.getField("Drop.03").value == "Small Size"

var expTplt1 = getTemplate("1K7-2");

expTplt1.spawn(numPages,false,false);

var expTplt2 = getTemplate("1K7-3");

expTplt2.spawn(numPages,false,false);

var expTplt3 = getTemplate("1K7-4");

expTplt3.spawn(numPages,false,false);

var expTplt4 = getTemplate("1K7-5");

expTplt4.spawn(numPages,false,false);

this.pageNum = 1; }

 

else { this.getField("1K.").display = display.visible; }

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
Community Expert ,
Sep 14, 2020 Sep 14, 2020

Copy link to clipboard

Copied

Don't use

var Drop2 = event.value;

var Drop3 = event.value;

at dropdown list 1

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
Community Expert ,
Sep 14, 2020 Sep 14, 2020

Copy link to clipboard

Copied

You can reference event.value as many times as you wish in your code, or you can assign it to a variable and then use that, like this:

 

var v = event.value;

if (v=="abc") {

// do something

} else if (v=="xxx") {

// do something else

}

etc.

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
Explorer ,
Sep 12, 2020 Sep 12, 2020

Copy link to clipboard

Copied

I'm not 100% sure what you mean, but i think you mean that you want to know which property field I am using... I hope.

 

As with my other javascript fields, I am using the "validate" dropdown property and NOT the "calculate" property.

Does that answer your question?

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
Enthusiast ,
Sep 13, 2020 Sep 13, 2020

Copy link to clipboard

Copied

It's not if( event.value == "Drop.01" ) { it should be Drop1 not Drop.01

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
Explorer ,
Sep 13, 2020 Sep 13, 2020

Copy link to clipboard

Copied

I'm sorry but that didn't make any difference to what I already had. The same exact thing happens.

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
Explorer ,
Sep 16, 2020 Sep 16, 2020

Copy link to clipboard

Copied

LATEST

So I figured it out and I will place a sample below. My problem was that I made the incorrect assumption that I could only have each event.value option once in the code (so I could only use the options of small, medium and large once each). After I figured that was wrong, all I had to do was place the other conditions. Hope that makes sense. There is probably a more efficient way to do this, but I could get this one to work, so I'm happy.

 

if (event.value == "Drop.01") { 

this.getField("1K.").display = display.visible;

}

else if (event.value == "Small Size") {

(event.value == (this.getField("Drop.02").value == "Small Size")) && ((event.value == this.getField("Drop.03").value == "Small Size")); {

var expTplt1 = getTemplate("1K1-2");

expTplt1.spawn(numPages,false,false);

var expTplt2 = getTemplate("1K1-3");

expTplt2.spawn(numPages,false,false);

var expTplt3 = getTemplate("1K1-4");

expTplt3.spawn(numPages,false,false);

this.pageNum = 1; } }

 

else if (event.value == "Small Size") {

(event.value == (this.getField("Drop.02").value == "Small Size")) && ((event.value == this.getField("Drop.03").value == "Medium Size")); {

var expTplt1 = getTemplate("1K10-2");

expTplt1.spawn(numPages,false,false);

var expTplt2 = getTemplate("1K10-3");

expTplt2.spawn(numPages,false,false);

var expTplt3 = getTemplate("1K10-4");

expTplt3.spawn(numPages,false,false);

this.pageNum = 1; } }

 

// The rest of the conditions...

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