9 Replies Latest reply on Jan 16, 2015 5:24 AM by ahlaj77

    Leap Year Date Issue (Example provided)

    ahlaj77

      Please see link for document:

      Dropbox - DateIssue.pdf

       

      When the FROM dropdown has 02/28/2016 selected, the date for Monday throws an error.

      The rest of the dates change but Monday does not change because it is supposed to be 02/29 (See Screenshot). Any help is appreciate! Thanks!!

       

      IssueDateScreenshot.png

        • 1. Re: Leap Year Date Issue (Example provided)
          try67 MVP & Adobe Community Professional

          First of all, you have an error in another script that's causing this error message to be shown each time you make a change in the drop-down:

          TypeError: DeptData[cDeptName] is undefined

          5:Field:Keystroke

          Also, there's a bug in your custom calculation code of the Monday field. The last line of it is:

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

          It should be:

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

           

          However, the issue you're seeing is most likely caused by a bug in Acrobat itself. You can overcome it by simply removing the Format setting of your date fields. You don't really need it anyway because their values are calculated so you can determine what format they should have in the calculation script.

          • 2. Re: Leap Year Date Issue (Example provided)
            ahlaj77 Level 1

            That worked! Thanks for your help!!

            • 3. Re: Leap Year Date Issue (Example provided)
              gkaiseril MVP & Adobe Community Professional

              First I would cleanup any errors that appear in the JavaScript console:

               

               

              DeptData[cDeptName] is undefined

              5:AcroForm:FromDate:Keystroke

              TypeError: DeptData[cDeptName] is undefined

              5:AcroForm:FromDate:Keystroke

               

              I would next learn how to convert a date string to the date object.

               

              Since you are formatting using the util.printd method, you can leave the days of the week field format to None.

               

              The setFieldValues function:

               

              function SetFieldValues(cDeptName)

              {

                this.getField("ToDate").value = event.target.value;

              }

               

              The custom calculation for the days of the week:

               

              var f = this.getField("txtDate1");

              // var d = new Date(f.value);

              // convert the date value with format to date object;

              var d = util.scand("mm/dd/yyyy", f.value);

              // advance by 1 day;

              d.setDate(d.getDate()+1);

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

               

              Adjust the number of days to advance as needed.

               

              Assuming that JavaScript is going always interpret the date string format may not always be a good approach.

              • 4. Re: Leap Year Date Issue (Example provided)
                ahlaj77 Level 1

                Okay :-) will do! Thanks for the extra help! I appreciate it very much

                • 5. Re: Leap Year Date Issue (Example provided)
                  gkaiseril MVP & Adobe Community Professional

                  I would use the following coddle for the custom keystroke code:

                   

                  if( event.willCommit == false )

                  {

                     if(event.changeEx== " ")

                       this.resetForm(["ToDate", "txtDate1",  "txtDate2",  "txtDate3",  "txtDate4",  "txtDate5",  "txtDate6",  "txtDate7"]);

                     else

                       SetFieldValues(event.changeEx);

                  }

                   

                  The strip the code from each day of the week and the to date.

                   

                  I would then use the following document level script:

                   

                   

                  function SetFieldValues(cStartDate)

                  {

                  var oStartDate = util.scand("mmm dd yyyy", cStartDate);

                  for (i = 0; i < 7; i++) {

                  console.println(i);

                  oStartDate.setDate(oStartDate.getDate() + 1);

                  this.getField("txtDate" +( i + 1)).value = util.printd("mm/dd", oStartDate);

                  } // end loop of days of the week;

                     this.getField("ToDate").value = util.printd("mm/dd", oStartDate);

                  }

                   

                  This will stop the dates being recalculated whenever any field used in a calculation is updated.

                  • 6. Re: Leap Year Date Issue (Example provided)
                    ahlaj77 Level 1

                    Okay :-) Thanks! Will give it a try :-) MUCH APPRECIATED!!!

                    • 7. Re: Leap Year Date Issue (Example provided)
                      ahlaj77 Level 1

                      Would I need to place a certain code in the following fields: txtDate1, txtDate2, etc?

                      • 8. Re: Leap Year Date Issue (Example provided)
                        gkaiseril MVP & Adobe Community Professional

                        Assign Sequential Date Values is a working example with day of the week validation.

                        • 9. Re: Leap Year Date Issue (Example provided)
                          ahlaj77 Level 1

                          Thank you :-)