3 Replies Latest reply on Mar 12, 2013 1:35 PM by gkaiseril

    Validate Date and block JavaScript page change

    Gdaimon
      how I can validate date acrobat, can block JavaScript page change, only change with a button?

       

        • 1. Re: Validate Date and block JavaScript page change
          try67 MVP & Adobe Community Professional

          Validate in what way?

          What's a "JavaScript page change"?

          • 2. Re: Validate Date and block JavaScript page change
            Gdaimon Level 1

            how to validate a date, and add and subtract two date fields
            Ej:
            * Current date 13/03/2013 => not let write
            * 03/09/2013 - 12/03/2013 = 3 days

            • 3. Re: Validate Date and block JavaScript page change
              gkaiseril MVP & Adobe Community Professional

              If you use the "util.scand" method date validation is part of the process. It either returns the number of milliseconds from the Epoch date used by JavaScript for the date time object the null value.

               

              Date Arithmetic has some sample scripts, but you need to keep in mind that Date and Time are not independent and using "new Date()" returns the date and time at the time that line of code is executed and that can cause issues for the computing of dates only.

               

              Are you sure of day count, most differences include the start and end dates in the number of days for the calculation.

               

              Custom calculation for today's date field (format is None):

               

              // get today's date an time

              var oToday = new Date();

              // set to start of day

              oToday.setFullYear(oToday.getFullYear(), oToday.getMonth(), oToday.getDate(), 0, 0, 0, 0)

              // set field value

              event.value = util.printd("d/mm/yyyy", oToday);

               

              Custom calculation for the difference in days field (format None):

               

              var cEnteredDate = this.getField("EnteredDate").value;
              var cToday = this.getField("Today").value;
              event.value = "";
              if(cEnteredDate != "" && cToday != "") {
              // process only if date values not empty
              // convert date strings to date time objectat midnight
              var oEnteredDate = util.scand("d/mm/yyyy", cEnteredDate );
              if (oEnteredDate == null) {
              app.alert("Error in processing entered date", 2, 0);
              }
              oEnteredDate.setFullYear(oEnteredDate.getFullYear(), oEnteredDate.getMonth(),oEnteredDate.getDate(), 0, 0, 0, 0) 

              var oToday = util.scand("d/mm/yyyy", cToday);
              if(oToday ==  null) {
              app.alert("Error converting today", 2,0);
              }
              oToday.setFullYear(oToday.getFullYear(), oToday.getMonth(),oToday.getDate(), 0, 0, 0, 0) 
              // convert date objects to days
              var nEnteredDate = Math.floor(oEnteredDate.getTime() / (1000 * 60 * 60 * 24));
              var nToday = Math.floor(oToday.getTime() / (1000 * 60 * 60 * 24));
              // compute & format the difference
              event.value = util.printf("%,0 1.0f", (nToday - nEnteredDate));
              }