Skip to main content
Participant
Apr 13, 2025 6:42 PM UTC
Answered

Keep disappearing text with a formulated field

Hi everyone,

I have a textbox with disappearing text and want to calculate the absolute value of another textbox. I added a custom calculation script in Properties > Calculate, but it overrides the disappearing text and shows "0" when there's nothing to calculate. I tried doing a nested if statement in the Calculate and Format sections, but I get NaN (which makes sense).  I included the scripts I used for each thing; the disappearing text script worked before I added the absolute value calculation.

 

Is there a way to have a textbox display disappearing text when the calculated value is "0"?

 

Thanks!

//Absolute Value Calculation in Properties > Calculate
event.value = Math.abs(Number(this.getField("($) Gross Up").valueAsString));

//Disappearing Text script in Properties > Format > Custom Format Script
if (!event.value) {
event.value = "$ Gross Up" ;
event.target.display = display.noPrint;
else {
event.target.textColor = color.black;
event.target.display = display.visible;
}

//My attempt at the nested if statement
var A = this.getField("($) Gross Up").value
if (A = 0){
    if (!event.value) {
    event.value = "$ Gross Up" ;
    event.target.display = display.noPrint;
    }else {
    event.target.textColor = color.black;
    event.target.display = display.visible;
    }
}else{
event.value = Math.abs(Number(A.valueAsString));
}

 

PDF Automation Station
Community Expert
Apr 24, 2025 12:28 AM UTC

You have problems with your script again.  This line is going to give you an error:

if (A==isNan) because isNan is not defined.  If you are trying to say "if A is not a number" it should be like this:

if(isNaN(A))

Also, you can only put else once in the statement.  Use else if before the last else.

5 replies

PDF Automation Station
Community Expert
Community Expert
Apr 13, 2025 7:41 PM UTC

Change A=0 to A==0

Translate
latifa_bAuthor
Participant
Apr 23, 2025 11:19 PM UTC

Sorry, this got a response much faster than anticipated! I tried that in the Format and Calculate tabs and got "NaN".

I updated the scripts to the following, but still got NaN:

//Custom Format Script of reference field
if (!event.value) {
event.value = "$ Gross Up";
event.target.textColor = color.gray
event.target.display = display.noPrint;
} 
else {
event.value = util.printf("%,.2f", event.value);
event.target.textColor = color.black
event.target.display = display.visible;
}

//Custom Calculate Script of calculating field
var A = this.getField("($) Gross Up").value
if (A == isNan){
    if (!event.value) {
    event.value = "$ Gross Up" ;
    event.target.display = display.noPrint;
    }else {
    event.target.textColor = color.black;
    event.target.display = display.visible;
    }
}else{
event.value = Math.abs(Number(A.valueAsString));
}

 

I think I need a line in the Custom Format Script of the reference field, ($) Gross Up, to format the text as a number when overriding the disappearing text. I found and added this, but the formatting wasn't changed. 

 

Any ideas?!

 

Thank you!

Translate
PDF Automation Station
Community Expert
Community Expert
Apr 24, 2025 12:28 AM UTC

You have problems with your script again.  This line is going to give you an error:

if (A==isNan) because isNan is not defined.  If you are trying to say "if A is not a number" it should be like this:

if(isNaN(A))

Also, you can only put else once in the statement.  Use else if before the last else.

Translate