I tried your script on a form in Designer 7.1 which I previewed as an Acrobat 7.0.5 Dynamic PDF. While I didn't have problems with the script toggling the presence of the field, the product field's value would always remain zero (0).
Then I modified the script to be as follows (in JavaScript):
if (fieldOne.rawValue > 0)
{
if (this.presence != "visible")
this.presence = "visible";
this.rawValue = fieldOne.rawValue * fieldTwo.rawValue;
}
else
{
if (this.presence != "invisible")
this.presence = "invisible";
this.rawValue = 0;
}
Using this script, everything worked fine: Both the toggling of the presence of the product field as well as its calculated number.
This made me wonder if there was a timing issue when setting a field's presence immediately after changing its value so I tried a configuration where I had two numeric fields: One field receives a number entered by the user while the other has a Calculate script on it which hides itself if the first field's value is zero or less and shows itself along with the value of the field field multiplied by 10.
This is the JavaScript I used on the "10 product" field:
if (NumericField4.rawValue > 0)
{
this.presence = "visible";
this.rawValue = 10 * NumericField4.rawValue;
}
else
{
this.presence = "invisible";
this.rawValue = 0;
}
Once again, this worked as expected. But when I changed the order of the operations such that the presence was being changed
after the value, while the presence was being set correctly, the value always remained zero (0).
So I believe this proves that there's a bug with setting the presence after setting the value in a Calculate script where the value always remains zero (0) and this also shows that there's a simple work-around. If you're still having problems with the presence while using the suggested work-around, it's possible you're either using a version of Acrobat which is prior to 7.0.7 and has worst symptoms than this latest version or that you're either previewing or you've saved your form in a
static PDF format.
Thank you for pointing-out this problem. I'll report it to Acrobat. Bare in mind, however, that the Calculate event was never meant for anything more than affecting a field's value based on a calculation. Of course, I, personally, understand (and see the value in) the desire to affect much more than a field's value in the Calculate event since it runs every time the value of a field on the form changes. But since it wasn't designed for that, one should always be careful when writing complex calculation scripts such as the one you were using.
Attached is my test form for you to try.
Stefan
Adobe Systems