How to prevent calculated fields from displaying zero?

Mentor ,
Oct 12, 2017

Copy link to clipboard

Copied

I have a PDF form that does some simple arithmetic: taking numerical entries from the user, adding or subtracting them, and then displaying the results in another field. Right now, all my calculation fields display 0.00, and they update as you add data. But if an user would rather print the form and hand write the numbers, how do you prevent the form from displaying (and printing) 0.00 in the calculated fields? I've tried this, and it doesn't work:

var cash = this.getField("Total Cash on Hand");
var petty = this.getField("Petty Cash");
var diff = cash.value - petty.value;
if (cash.value == "NaN" || petty.value == "NaN") { event.value = "" } else event.value = diff;
Adobe Community Professional
Correct answer by gkaiseril | Adobe Community Professional

I would use the valueAsString property for retrieving the values of the field values for cash and petty.

event.value = "";

var cash = this.getField("Total Cash on Hand");

var petty = this.getField("Petty Cash");

if (cash.valueAsString != "") {

event.value = cash.value - petty.value

I would expect you only need to test the cash on hand for a value and assume the petty cash is zero unless you need that value to explicitly entered.

Using the valueAsString property of a field retrieves the actual contents of a field and does not perform any automatic reformatting or formatting of the value of the field. JavaScript automatically changes a null string to zero and removes leading zeros from fields formatted as a numeric or percentage, while the valueAsString property retains the null value or leading zeros of the field.

TOPICS
Acrobat SDK and JavaScript, Macintosh

Views

184

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

How to prevent calculated fields from displaying zero?

Mentor ,
Oct 12, 2017

Copy link to clipboard

Copied

I have a PDF form that does some simple arithmetic: taking numerical entries from the user, adding or subtracting them, and then displaying the results in another field. Right now, all my calculation fields display 0.00, and they update as you add data. But if an user would rather print the form and hand write the numbers, how do you prevent the form from displaying (and printing) 0.00 in the calculated fields? I've tried this, and it doesn't work:

var cash = this.getField("Total Cash on Hand");
var petty = this.getField("Petty Cash");
var diff = cash.value - petty.value;
if (cash.value == "NaN" || petty.value == "NaN") { event.value = "" } else event.value = diff;
Adobe Community Professional
Correct answer by gkaiseril | Adobe Community Professional

I would use the valueAsString property for retrieving the values of the field values for cash and petty.

event.value = "";

var cash = this.getField("Total Cash on Hand");

var petty = this.getField("Petty Cash");

if (cash.valueAsString != "") {

event.value = cash.value - petty.value

I would expect you only need to test the cash on hand for a value and assume the petty cash is zero unless you need that value to explicitly entered.

Using the valueAsString property of a field retrieves the actual contents of a field and does not perform any automatic reformatting or formatting of the value of the field. JavaScript automatically changes a null string to zero and removes leading zeros from fields formatted as a numeric or percentage, while the valueAsString property retains the null value or leading zeros of the field.

TOPICS
Acrobat SDK and JavaScript, Macintosh

Views

185

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 12, 2017 0
Adobe Community Professional ,
Oct 12, 2017

Copy link to clipboard

Copied

I would use the valueAsString property for retrieving the values of the field values for cash and petty.

event.value = "";

var cash = this.getField("Total Cash on Hand");

var petty = this.getField("Petty Cash");

if (cash.valueAsString != "") {

event.value = cash.value - petty.value

I would expect you only need to test the cash on hand for a value and assume the petty cash is zero unless you need that value to explicitly entered.

Using the valueAsString property of a field retrieves the actual contents of a field and does not perform any automatic reformatting or formatting of the value of the field. JavaScript automatically changes a null string to zero and removes leading zeros from fields formatted as a numeric or percentage, while the valueAsString property retains the null value or leading zeros of the field.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 12, 2017 0
Mentor ,
Oct 13, 2017

Copy link to clipboard

Copied

Thanks very much!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 13, 2017 0
Adobe Community Professional ,
Oct 13, 2017

Copy link to clipboard

Copied

You should place this as a Validation script:

event.target.textColor = event.value == 0 ? color.white : color.black;

If value is zero, it is turned to white (adjust to the background color) so it becomes invisible on screen and on print.

Without breaking any following calculation process with a NaN value.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 13, 2017 0