Expand my Community achievements bar.

How to get FormCalc to recognize a value as numeric

Avatar

Former Community Member
I have spent several hours on this with no resolution and am hoping someone can help.



I'm working on a form in LiveCycle 8. I'm trying to show/hide Field2 based on the value of Field1, but FormCalc seems not to recognize the value of Field1 as a number. This is the script that doesn't work:



if (Field1.rawValue < 2.5) then

Field2.presence = "invisible";

else

Field2.presence = "visible";

endif



I've also tried Field1.value, but it doesn't work either.



However, this works:



if (2 < 3) then

Field2.presence = "invisible";

else

Field2.presence = "visible";

endif



If I manually change (2 < 3) to (2 > 3), the script also works perfectly in reverse.



I've messageBoxed the value of Field1, and it displays the number I expect (i.e., it's not empty or too big or too small).



How can I manipulate the value of Field1 so the first script will work? Or if there's some other workaround, I'm open to it.



Thanks in advance!



Kathryn
6 Replies

Avatar

Level 5
One simple way to resolve the situation is making those fields as numaric fields.



Convertion operations in FormCalc is not made simple. So other promissing way to deal the situation is change this to JS code.



if (Field1.rawValue < 2.5) {

Field2.presence = "invisible";

}else{

Field2.presence = "visible";

}

Avatar

Former Community Member
Sorry, I should have mentioned that the fields are already numeric, which makes this problem all the more puzzling. I also tried JavaScript and it didn't solve the problem. Any other ideas?

Avatar

Level 5
I prefer using "hidden" in place of "invisible".

And which event and with reference which field are you trying to use this code?

Avatar

Level 7
JavaScript sometimes makes decisions as to what is a number and not. Depending upon how a number is inserted into a field can cause JavaScript to think a numeric string is a character string, and it is but a special case. This usually happens when using special format or the "util.pirntf()" method.So you can either use the multiplicative itdentity to force a field value to a numeric value or use the "Number()" constrictor.



// multiply by 1

if ( 1 * Field1.rawValue < 2.5) {

Field2.presence = "invisible";

}else{

Field2.presence = "visible";

}



// or use the numeric constrictor

if (Number(Field1.rawValue) < 2.5) {

Field2.presence = "invisible";

}else{

Field2.presence = "visible";

}

Avatar

Former Community Member
Kathryn - Are your numeric fields in the Value tab, type "Calculated, user can override?"

Avatar

Former Community Member
Gretchen,



Thanks for your reply! I believe the type was calculated--read only.



I figured out some resolution to this problem... the trouble is, now I don't remember what it was!!! Too much going on :) But thanks for checking back.



Kathryn