Skip to main content
Participant
April 13, 2025
Answered

Keep disappearing text with a formulated field

  • April 13, 2025
  • 1 reply
  • 560 views

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));
}

 

Correct answer PDF Automation Station

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.

1 reply

PDF Automation Station
Community Expert
Community Expert
April 13, 2025

Change A=0 to A==0

latifa_bAuthor
Participant
April 23, 2025

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!

PDF Automation Station
Community Expert
Community Expert
April 24, 2025

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.