6 Replies Latest reply on May 11, 2012 7:10 AM by gkaiseril

    How do I clear a form of calculated values

    sfriedman426 Level 1

      I've created a form with most fields having calculated values from javascript. I've tested the form and now when I go to save it, it won't clear the values. How do I do this?

        • 1. Re: How do I clear a form of calculated values
          Bernd Alheit Adobe Community Professional & MVP

          You can use the Javascript method resetForm.

          • 2. Re: How do I clear a form of calculated values
            gkaiseril MVP & Adobe Community Professional

            Exactly what are you trying to calculate?

             

            Do any of the source data fields have a default value?

             

            Is JavaScript assuming a value for a null or empty field?

             

            See Calculated Fields Not reseting with Forms Reset for some sample code that will show you what is happening.

            • 3. Re: How do I clear a form of calculated values
              sfriedman426 Level 1

              It might be easier if you look at the form itself

              • 4. Re: How do I clear a form of calculated values
                gkaiseril MVP & Adobe Community Professional

                You need to read how events are processed in Acrobat forms. Resetting the fields will cause all calculation scripts to be processed if there is any filed that has a calculation.

                 

                Now you have to be aware that if a date string is processed by the util.scand method and it has a null value then the current date value is used. So you should be seeing today's date + 7 days.

                 

                var SunDate = this.getField("FirstSunday").value; // get date string

                if(SunDate != "") {

                // process if SunDate field not blank or null

                var pDate = util.scand("mmm/dd/yy", SunDate); // convert to object

                var nDay = 1000 * 60 * 60 * 24; // define 1 day in milliseconds

                var nDate = pDate.getTime() + (7 * nDay); // add 7 days as milliseconds

                pDate = new Date(nDate); // convert milliseconds to date object

                event.value = util.printd("mm/dd/yy", pDate); // format result 

                } else {

                event.value = "";

                }

                 

                console.show();
                console.clear();
                console.println("SunDate: " + SunDate);
                console.println("pDate: " + pDate);

                 

                You will have to provide some access to the form.

                • 5. Re: How do I clear a form of calculated values
                  sfriedman426 Level 1

                  I think I see – So if the StartDate field is left blank, all the calculations based upon it default to Today’s value – hence the results I get in those fields. Sooooo…… how can I clear the fields. The script you provided still does not clear them and the SunDate value remains stuck at Today. Do I need to convert it to a string value?

                  • 6. Re: How do I clear a form of calculated values
                    gkaiseril MVP & Adobe Community Professional

                    It works for me when I place the provided script in the "Custom Calculation JavaScript" for a different field.

                     

                    Have you checked the JS console for errors?

                     

                    Does the console popup with any messages?

                     

                    Try this script, it will catch a format error and missing field.

                     

                    var SunDate = this.getField("FirstSunday").value; // get date string
                    try{
                    if(SunDate != "" & SunDate != " ") {
                    // process if SunDate field not blank or null
                    var pDate = util.scand("mmm/dd/yy", SunDate); // convert to object
                    if(pDate != null) {
                    var nDay = 1000 * 60 * 60 * 24; // define 1 day in milliseconds
                    var nDate = pDate.getTime() + (7 * nDay); // add 7 days as milliseconds
                    pDate = new Date(nDate); // convert milliseconds to date object
                    event.value = util.printd("mm/dd/yy", pDate); // format result 
                    } else {
                    // trap error in date format
                    app.alert("Invalid date or format!\nReenter valid date in the format \"mm/dd/yy\"", 0, 1);
                    event.value = "";
                    event.rc = false;
                    } // end pDate null
                    } else {
                    event.value = "";
                    } // end SunDate not null
                    } catch(e) {
                    console.show();
                    }
                    console.show();
                    console.clear();
                    console.println("SunDate: " + SunDate);
                    console.println("pDate: " + pDate);