7 Replies Latest reply on Feb 13, 2018 8:46 AM by rwiamacy

    Don't repopulate the Date , Mate.

    rwiamacy Level 1

      I have a field that populates a date when the form is created. I dont want it to repopulate every time the PDF opens after that.

      My code:

       

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

      f.value = util.printd("mm/dd/yyyy)", new Date());

       

      How do I do the null check?

        • 1. Re: Don't repopulate the Date , Mate.
          Thom Parker Adobe Community Professional

          A simple way to check for an empty field is to test for an empty string

          if(f.value != "")
              f.value = util.printd("mm/dd/yyyy)", new Date());
          

           

          This also works the same

          if(f.value.length)
              f.value = util.printd("mm/dd/yyyy)", new Date());
          

           

          This is the one I use cause it ignores entered spaces

          if(/^\s*$/.test(f.value))
              f.value = util.printd("mm/dd/yyyy)", new Date());
          

           

           

          However, now you have the issue of keeping a clean form available for opening. What happens when someone saves it back to the same name? No more blank form. You'll have to manually reset it and save it back.

          • 2. Re: Don't repopulate the Date , Mate.
            gkaiseril MVP & Adobe Community Professional

            Besides checking the value of the field, one can test the  default value of the field and set the value of default field. This approach will keep the open date if the form is cleared or reset by JavaScript of any menu option. To set the form up for saving with the date field cleared one only needs to clear the "Default value" on the options tab.

             

            var oField  = this.getField("ExamDate");

            if(oField.defaultValue = "")

            {

                  oField.devaultValue = util.printd("mm/dd/yyyy)", new Date());

                 oField.value = oField.defautlValue;

                 oField.readonly = true;

            }

            1 person found this helpful
            • 3. Re: Don't repopulate the Date , Mate.
              Thom Parker Adobe Community Professional

              Nice variation!! However, if you set the default value then a reset will never clear the date, and you can never get a new date on a clean form. The strategy for this really needs to be thought out. I think this type of document script only works when you have a clear form delivery system. If people are just copying it from a shared drive it should have a Form Prep button that clears the form and sets the current date.

              1 person found this helpful
              • 4. Re: Don't repopulate the Date , Mate.
                rwiamacy Level 1

                Thank you !!!!

                • 5. Re: Don't repopulate the Date , Mate.
                  rwiamacy Level 1

                  My code looks like this:

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

                   

                  if(f.value != "") 

                       f.value = util.printd("mm/dd/yyyy)", new Date());

                   

                  Its at the document level but the date is still updating. 

                  • 6. Re: Don't repopulate the Date , Mate.
                    try67 MVP & Adobe Community Professional

                    You want to update the field if the value is not empty? That doesn't make much sense...

                    I think you want to update it if it is empty. If that's the case, change the second line of your code to:

                    if (f.valueAsString == "")

                    • 7. Re: Don't repopulate the Date , Mate.
                      rwiamacy Level 1

                      HA!!!!!! Thank yoooooooooouuuuuuuu!!!!!