20 Replies Latest reply: Mar 11, 2012 1:51 PM by GKaiseril RSS

    Remove 0 Value in Calculated Field

    Community Member
      I copied the below question for another post here as it asks the question perfectly.

      "I set up an invoice form to calculate totals from quantity x unit price. Every line has this formula, however the users may not have a priced item on every line of the form. My total column shows a $0.00 value until I input data. I'd rather have nothing show in that column unless quantity and price are entered. Is that possible?"

      However, and I apologize, but I don't understand the answer that was posted. This is the first time I've needed a calculated field -- and I've not done scripting in Acrobat before.

      Can someone walk me through the exact steps of how to enter and what to enter in the form to remove "0" values from the form?

      Thanks, in advance, for any and all help.
        • 1. Re: Remove 0 Value in Calculated Field
          GKaiseril ACP/MVPs
          What program did you use to create the forms?

          There are big differences in the code location and code language and syntax between Acrobat forms and LiveCycel Designer forms.

          You will have to test the to see if the result is zero and if it is zero you need to either make it an empty or null string.
          • 2. Re: Remove 0 Value in Calculated Field
            Community Member
            Thanks for your reply. I created the forms in Adobe Acrobat 8.0 Pro.
            • 3. Re: Remove 0 Value in Calculated Field
              George_Johnson ACP/MVPs
              I believe you're referring to this thread: http://www.adobeforums.com/webx?128@@.59b5ca88

              If so, what part is not clear?

              George
              • 4. Re: Remove 0 Value in Calculated Field
                Community Member
                I sincerely appreciate your reply and help with this.

                What I'm not clear on is:

                If I do the document function (Advanced, Document Functions, Document Javascripts)....
                a. I create a new Script (i.e., named "ds_format". Do I enter the code exactly as you have written? I did try this, and the zeros didn't disappear. But I don't think I understood how to finish.....

                Then, the other functions you have (function ds_keystroke and //custom Format Script.
                To be honest, I'm just not clear on where to put these within the document. Should one or both go into field properties under Calculate tab, then Custom Calculation Script?

                Again, I sincerely appreciate your help and I apologize for being such on novice on this.
                • 5. Re: Remove 0 Value in Calculated Field
                  DimitriM ACP
                  Hi Diana,

                  Since you are so new to Acrobat scripting, this post about how to find scripts and where scripts are located in PDF forms and documents-
                  http://www.pdfpdfpdfpdf.com/2009/02/how-to-find-scripts-in-a-pdf/

                  may be helpful for you. There is a link for a PDF download at the end of the post.

                  Hope this helps,

                  Dimitri
                  WindJack Solutions
                  www.windjack.com
                  www.pdfscripting.com
                  • 6. Re: Remove 0 Value in Calculated Field
                    George_Johnson ACP/MVPs
                    No need to apologize, it just wasn't clear to me what was wrong.

                    If you've successfully added the document-level functions that were posted in the other topic, your next step is to set up the text field to call those functions. You would not use a custom calculation script, but rather a custom Format and Keystroke script.

                    To do that, open up the Text Field properties window, select the Format tab, and select a format category of "Custom". You should then see where you can place a custom Format script and a custom Keystroke script.

                    This is what you should use as the custom Format script:

                    ds_format();

                    And this is what you should use as the custom Keystroke script:

                    ds_keystroke();

                    These two functions are defined in the document-level JavaScript that you set up previously. Post again if this is not clear or doesn't work for you.

                    George
                    • 7. Re: Remove 0 Value in Calculated Field
                      Community Member
                      Thanks! I appreciate it!
                      • 8. Re: Remove 0 Value in Calculated Field
                        Community Member
                        Thanks, again, so much. I think I got it, the procedure that is! But, but the 0 is still there.

                        This does now sound like a simple thing if you know the code. But apparently I'm not there yet!

                        This is what I did.

                        Under Advanced, Document Processing, JavaScript Functions.
                        Entered two different scripts, as follows (this is exactly how I entered them):
                        ----------------------------------
                        SCRIPT 1
                        Name: ds_format
                        Script:
                        function ds_format()
                        {
                        if (+event.value) {
                        //$ format for nonzero values
                        AFNumber_Format(2,0,0,0,"$",true);
                        } else {
                        //Don't show anything if result is zero event.value="";}
                        }
                        }

                        SCRIPT 2
                        Name: ds_keystroke
                        Script:
                        function ds_keystroke() {

                        AFNumber_Keystroke(2, 0, 0, 0, "$", true);

                        }
                        -------------------------------------
                        Then, under the calculated field properties (in my case, Total Cost),
                        Format Tab, Custom Format, Custom Format Script section, I selected edit and typed in:
                        ds_format();

                        Ditto above, but under Custom Keystroke Script:
                        ds_keystroke();
                        • 9. Re: Remove 0 Value in Calculated Field
                          George_Johnson ACP/MVPs
                          The problem may be the following line:

                          > //Don't show anything if result is zero event.value="";}

                          It should really be three lines:


                          // Don't show anything if result is zero

                          event.value="";

                          }


                          I can post a sample document if you can't get this to work.

                          George
                          • 10. Re: Remove 0 Value in Calculated Field
                            Community Member
                            Really appreciate you hanging in there with me on this.

                            The code in the box actually looks like below (sorry about before). However, I will point out that the lne "//don't ....." word wraps around all by itself. If I try to break the line (return key), I get syntax errors.

                            Would you mind posting a sample? I am very sorry to be such on pain on this. (Or inept, whatever the case may be.) :-)

                            Thanks, again.

                            function ds_format()
                            {
                            if (+event.value) {
                            //$ format for nonzero values
                            AFNumber_Format(2,0,0,0,"$",true);
                            } else {
                            //Don't show anything if result
                            is zero event.value="";}
                            }
                            }
                            • 11. Re: Remove 0 Value in Calculated Field
                              George_Johnson ACP/MVPs
                              No problem. Here is a sample PDF that demonstrates this:

                              https://share.acrobat.com/adc/document.do?docid=9969aa7b-f43e-4a86-9d47-f77aaf5462c3

                              George
                              • 12. Re: Remove 0 Value in Calculated Field
                                Community Member
                                It worked!!
                                (I copied yours into mine and it worked!).

                                Thank you so much for all your time and patience.
                                • 13. Re: Remove 0 Value in Calculated Field
                                  Community Member
                                  George - one last question.....

                                  If I don't want the "$" to appear for certain fields (some I do want the dollar sign on, some I do not), can I enter an additional script to reference in those text boxes ....something like:

                                  function ds_keystroke02() {

                                  AFNumber_Keystroke(2, 0, 0, 0, " ", true);

                                  }
                                  • 14. Re: Remove 0 Value in Calculated Field
                                    George_Johnson ACP/MVPs
                                    Sure you can. Have you tried it? But instead of a single space, you can have nothing by specifying an empty string. Just use quotes with nothing in between.

                                    You could also create a more general purpose set of functions such as:

                                    function ds_format(prefix_char) {

                                    if (+event.value) {
                                    // $ format for nonzero values
                                    AFNumber_Format(2, 0, 0, 0, prefix_char, true);
                                    } else {
                                    // Don't show anything if result is zero
                                    event.value = "";
                                    }
                                    }

                                    function ds_keystroke(prefix_char) {

                                    AFNumber_Keystroke(2, 0, 0, 0, prefix_char, true);

                                    }

                                    And call the functions by specifying the prefix character you want to use as a parameter. For example:

                                    ds_keystroke("$");

                                    or

                                    ds_keystroke("");

                                    George
                                    • 15. Re: Remove 0 Value in Calculated Field
                                      Community Member
                                      Thanks, again, for your help and quick responses. I haven't had time to concentrate back on this.....they apparently want me to do other things at work too! :-)

                                      I'll tuck all your wonderful information away for future modifications.

                                      Thanks, again!
                                      • 16. Re: Remove 0 Value in Calculated Field
                                        Gressa Community Member

                                        I am having the same problem with having an unwanted 0 in the total line. I went through all the same steps but it didn't work. It looks like copying the script from the link that George posted is the solution but when I clicked on the link it came up as an error, I'm guessing it's just not there any more but I was wondering if I could get that sample PDF. Thanks!

                                        • 17. Re: Remove 0 Value in Calculated Field
                                          try67 ACP/MVPs

                                          Enter this code as the custom validation script of your field:

                                          if (event.value==0) event.value = "";

                                          • 18. Re: Remove 0 Value in Calculated Field
                                            Gressa Community Member

                                            Thanks for your help. I got the script to work, however since I had to input script, now I have an unwanted $ sign and decimal points. How do I incroporate in the script how to get rid of the $ sign as well as the decimal points? Please advise. Thanks!

                                            • 19. Re: Remove 0 Value in Calculated Field
                                              try67 ACP/MVPs

                                              You've probably set the formatting of the field to Number with the currency sybmol and decimal points...

                                              • 20. Re: Remove 0 Value in Calculated Field
                                                GKaiseril ACP/MVPs

                                                For just a plain numeric field with no currency symbol or special negative value display, I would use the following custom validation script:

                                                 

                                                if(event.value == 0) {

                                                event.value = "";

                                                } else {

                                                event.value = event.value

                                                }

                                                 

                                                For field formatted with a currency symbol of percentage, I would use a custom validation script with the JS function to dynamically format the field as a number or percentage.

                                                 

                                                AFNumber_Format({nDec: 2, sepStyle: 0, negStyle: 0, currStyle: "", strCurrency: "", bCurrencyPrepend: false})

                                                AFPercent_Formatfunction AFPercent_Format({nDec: 2, sepStyle: 0, bPercentPrepend: false})