4 Replies Latest reply on Sep 20, 2013 7:24 AM by ahlaj77

    Auto/Manually enter a date

    ahlaj77

      Hello and thank you in advance for your help!  Currently I have a form that has text box using an auto date. Then I have three more text boxes that shows a date 7 days, 14 days, and 28 days ahead. I am working on this for a client and they would also like to be able to manually change the dates in any of those text boxes as well. I am having a hard time wrapping my head around what I need to do and need some guidance. Whenever I try to manually enter a date, it  immediately calculates and reverts back to today's date (and updates the other boxes as well).
      Dates.jpg

        • 1. Re: Auto/Manually enter a date
          MarkWalsh Level 4

          Try moving your script from the Calculation to Validation script, but only calculate if event.value is empty.

           

          Alternately, you could set up a custom Format script instead of the Calculation script - if the event.value is empty, use your calculated value. One caveat: This would require you to format the date manually in the script since you no longer have access to the date format features.

          • 2. Re: Auto/Manually enter a date
            ahlaj77 Level 1

            Thank you for your reply. Yes you are right, my scripts are currently in the "Custom Calculation Script" section

            Here are the scripts I use to give you a better idea:

             

            First Text Box:

            // get the current date's date object for the first text box

            var oDate = new Date();

             

            // set the field value

            this.getField("FromDate2").value = util.printd("mm/dd/yyyy", oDate);

             

            Second Text Box (7 days):

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

            var d = new Date(f.value);

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

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

             

            Third Text Box (14 days):

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

            var d = new Date(f.value);

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

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

             

            Fourth Text Box (28 days):

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

            var d = new Date(f.value);

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

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

            • 3. Re: Auto/Manually enter a date
              MarkWalsh Level 4

              To get you started, try this in the Custom Format script:

               

              var f
              var d
              if (event.value == '') {
                  f = this.getField("FromDate2").value;
                  d = new Date(f);
                  d.setDate(d.getDate()+7);
              } else {
                  f = event.value;
                  d = new Date(f);
              }

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

               

               

              Note, that this does not do any validation that a proper date has been entered into either text field.

              • 4. Re: Auto/Manually enter a date
                ahlaj77 Level 1

                Awesome! Thank you so much! :-)