Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Cannot toggle field between visible & invisible

Avatar

Former Community Member
There is a defect with Designer's scripting that prevents toggling a numberic calculated field between being visible and invisible. Here is a sample calculated field script that reproduces the problem:



if (fieldOne.rawValue > 0)

{

this.rawValue = fieldOne.rawValue * fieldTwo.rawValue;

this.presence = "visible";

}

else

{

this.presence = "invisible";

this.rawValue = 0;

}



Note that the same defect is present when using an equivilent FormCalc script.
5 Replies

Avatar

Former Community Member
In general you should make sure the last line that will be processed in your calculation script is the one that sets the value of the field. So if you change your script to this, it should work:



if (fieldOne.rawValue > 0)

{

this.presence = "visible";

this.rawValue = fieldOne.rawValue * fieldTwo.rawValue;

}

else

{

this.presence = "invisible";

this.rawValue = 0;

}



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
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

Avatar

Former Community Member
Stefan, I don't think this is a bug. The value of the field will always be the return value of the last statement executed. If you were to do something like:



return DropDownField1.presense = "invisible";



it would be like saying



return "invisible";



Since "invisible" is not a valid number it sets the value of the NumericField to 0.



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
Interesting. I didn't realize that's what it did -- hence your suggestion to always end with setting the field's value.



Thanks for pointing that out, Chris (and I'm sure the Acrobat Team thanks you as well... ;) )!



Stefan

Adobe Systems

Avatar

Former Community Member
Thanks for looking into this guys. I completely understand that this is one of those bugs where some tricky tradeoffs are involved. As it stands right now though, it would be very difficult for the average person (and even above-average person) to understand why things aren't working, so I think you'd want to at least somehow warn the user "Hey, hey - whoah - you're assigning a string to numeric field? Dude, what is WRONG with you?!".