Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Saving issue!

Avatar

Level 2

we have two drop down fields: A & B

When i pick a value from drop down A, i coded it so a value from list B will pop up automatically.

My code for that is:

<

calculate override="warning">

<

script>if (A.rawValue &gt;= 1 and A.rawValue &lt;= 4) then

B.rawValue

else

B.rawValue

endif</

script>

</

calculate>

whenever i change the value in A, i save it. but when i go back and open the file again, the value is changed

is this a bug in the program, or is the code above wrong?

THANKS!

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

Here is an else if statement in Javascript that works its way up the bound value of the dropdown (from 1 to 12).

if (this.rawValue <= 3)

{

     groupName.rawValue = "Group 1 fruits";

     TestList3.rawValue = null;

     TestList3.clearItems();

     TestList3.addItem("two jars"); 

     TestList3.addItem("three jars");

     TestList3.addItem("four jars"); 

}


else if (this.rawValue > 3 && this.rawValue <= 7)

{

     groupName.rawValue = "Group 2 fruits";

     TestList3.rawValue = null;

     TestList3.clearItems();

     TestList3.addItem("one bowl"); 

     TestList3.addItem("two scoops");

     TestList3.addItem("three scoops"); 

}


else if (this.rawValue > 7 && this.rawValue <= 10)

{

     groupName.rawValue = "Group 3 fruits";

     TestList3.rawValue = null;

     TestList3.clearItems();

     TestList3.addItem("Choice for group 3 fruit"); 

     TestList3.addItem("Choice for group 3 fruit");

     TestList3.addItem("Choice for group 3 fruit"); 

}


else

{

     groupName.rawValue = "Group 4 fruits";

     TestList3.rawValue = null;

     TestList3.clearItems();

     TestList3.addItem("Choice for group 4 fruit"); 

     TestList3.addItem("Choice for group 4 fruit");

     TestList3.addItem("Choice for group 4 fruit"); 

}

Hope that helps,
Niall

View solution in original post

12 Replies

Avatar

Level 10

Hi,

Not a bug.

If you go to File > Form Properties > Default tab there is an option to preserve script changes. Select Automatic:

Parallels Desktop1.png

That should fix it for you,

Niall

Avatar

Level 2

Thanks Niall!

I tried your suggestion today, however, the problem is still around.

I looked further into the coding, and the problem seems to be caused by multiple fields in the form referred to the same list of codes.

EX:  multiple field (A, B, C..)  corresponding to the same master list ( Alpha) …

If we pick x in A to save, it will yield a number in Alpha. When open the file, it will still be x.

But if we pick y in A (that is different from x) to save, then reopen, it’ll jump back to x…..it seems that for some reason, Alpha will remain the same, while the field will only remember the first value we entered (in this case, x ).

Is there way we can fix this problem without creating repetitive list for each field?

thank you for your input!

Avatar

Level 10

Hi,

Are you editing the script in the script editor window? This is normally at the top of the window.

The script in your first post looks funny. Did you copy it from the XML Source?

The other thing I would look at is the binding for the dropdowns in the Object > Binding tab. If the specify values is ticked, then the bound values should be different, otherwise the dropdown may revert to the first item with the same bound value.

Can you share the form? Acrobat.com or similar.

Niall

Avatar

Level 2

thanks for replying so quickly, Niall.

YES!..that is exactly what is happening. the dropdown may revert to the first item with the same bound value...is there a way around that? or does everything in the dropdown need to have a different bound value?

i can send u the pdf for the problem fields but i can't seem to find the link to insert the file...

Avatar

Level 10

Hi,

The ability to attach files to a post is down (since Feb...).

You can use a file sharing website, like https://acrobat.com (free, but must register) or https://www.yousendit.com/

In both cases you will need to ensure that it is published and share the URL here.

However I don't think there will be a way around this. The object value is determined by the bound value (when this is specified). So when the form is being opened the data is merged with the form layout. Acrobat/Reader sees that the dropdown has a value and then displays the appropriate item from the list. It will display the first item that has the bound value that is equal to the objects value.

You will probably have to set different bound values and then have additional scripting to take appropriate action, based on the user's selection. So:

Display valueBound value
Choice A1
Choice B2
Choice C3
Choice D4

Then in the exit event you could have script that deals with Choices B, C and D as if they had the same effect

if (this.rawValue >= 2)

{

     do something appropriate for choices B, C, or D

}

else

{

     do something appropriate for choices A

}

Hope that helps,

Niall

Avatar

Level 2

http://www.yousendit.com/download/YWhNek9uQVNwaFJFQlE9PQ

here is the link to the file. I have multiple items in testlist that are bound by only 2 values (1 and 2). everytime i save,  it keeps reverting back to the first value.

thanks!

Avatar

Level 10

OK,

I have the form. The if statement is fruitless ;-)

if (TestList.rawValue >= 1 and TestList.rawValue <= 4)

TestList can only have a value of 1 or 2, so the if statement will always be true.

It may be that the real form has more than these choices/bound values. So what I have done is take all the items that were bound to 1 and grouped them at the top of the list. Then the items bound to 2, I have grouped at the end.

Now in the exit event I have an if statement that changes a field. This is just an example, you don't necessarily need an additional object.

Also when dealing with dependant dropdowns, one option is to change the items in the list depending on the first choice. I have added an extra dropdown. The script is all in the exit event of the first dropdown. The other option is to script the second dropdown in the preOpen event to look back at the selected value in the first dropdown.

Sample here: https://acrobat.com/#d=xxzByygROzQpejphv4oNcA

Hope that helps,

Niall

Avatar

Level 2

thank you so much for your help!

i just have 1 more question..what if i have more than 2 groups....i tried doing an elseif statement but it didn't work for me. Is there another way?

thanks!

Avatar

Correct answer by
Level 10

Hi,

Here is an else if statement in Javascript that works its way up the bound value of the dropdown (from 1 to 12).

if (this.rawValue <= 3)

{

     groupName.rawValue = "Group 1 fruits";

     TestList3.rawValue = null;

     TestList3.clearItems();

     TestList3.addItem("two jars"); 

     TestList3.addItem("three jars");

     TestList3.addItem("four jars"); 

}


else if (this.rawValue > 3 && this.rawValue <= 7)

{

     groupName.rawValue = "Group 2 fruits";

     TestList3.rawValue = null;

     TestList3.clearItems();

     TestList3.addItem("one bowl"); 

     TestList3.addItem("two scoops");

     TestList3.addItem("three scoops"); 

}


else if (this.rawValue > 7 && this.rawValue <= 10)

{

     groupName.rawValue = "Group 3 fruits";

     TestList3.rawValue = null;

     TestList3.clearItems();

     TestList3.addItem("Choice for group 3 fruit"); 

     TestList3.addItem("Choice for group 3 fruit");

     TestList3.addItem("Choice for group 3 fruit"); 

}


else

{

     groupName.rawValue = "Group 4 fruits";

     TestList3.rawValue = null;

     TestList3.clearItems();

     TestList3.addItem("Choice for group 4 fruit"); 

     TestList3.addItem("Choice for group 4 fruit");

     TestList3.addItem("Choice for group 4 fruit"); 

}

Hope that helps,
Niall

Avatar

Level 2

HI Niall,

I don't know why my numbers are in blue...there is no output in my Priority textfield

if (this.rawValue <= 2 )

{

Priority.rawValue = "PCAT I";

}

else if (this.rawValue >3 && <

= 5 )

{

Priority.rawValue = "PCAT II";

}

else

{

Priority.rawValue = "PCAT III";

}

thanks!

Avatar

Level 10

Hi,

Can you just verify that you are inputting/editing the script in the script editor and that the language is set to Javascript:

LittleSnapper1.png

Also the second if statement is incorrect. You need to explicitly test this.rawValue for each condition. So it would look like:

else if (this.rawValue > 3 && this.rawValue <= 5)

{

     ...

It should work then,

Niall

Avatar

Level 2

yes it worked! thank you so much!!