3 Replies Latest reply on Oct 13, 2017 5:53 AM by KrisHunt

    How to prevent calculated fields from displaying zero?

    KrisHunt Level 4

      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;
        • 1. Re: How to prevent calculated fields from displaying zero?
          gkaiseril MVP & 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.

          • 2. Re: How to prevent calculated fields from displaying zero?
            JR_Boulay Adobe Community Professional

            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.