Date Validation

Home Forums Classic DFFS Date Validation

Viewing 2 reply threads
  • Author
    Posts
    • #37509
      Sanchez
      Participant

        I need to do a date validation to ensure date entered is between a start and end date field values. Can you please advise how I can do that? The following code works on false but does not save if true. Also I need to allow for blank fields as well.

        function dffs_PreSaveAction(){

        var startDate = spjs.utility.getDateFieldAsDateObject(‘StartDate’);
        var endDate = spjs.utility.getDateFieldAsDateObject(‘EndDate’);
        var dateAnswer1 = spjs.utility.getDateFieldAsDateObject(‘DateAnswer1’);

        if (dateAnswer1 < startDate || dateAnswer1 > endDate) {
        alert(‘DateAnswer1 must be greater than StartDate and less than EndDate’);
        return false; // Return false to indicate validation failure
        }

        return true; // Return true to indicate validation success
        }

      • #37510
        Sanchez
        Participant

          Please disregard, I was able to get the following to work:

          function dffs_PreSaveAction(){

          var startDate = spjs.utility.getDateFieldAsDateObject(‘StartDate’);
          var endDate = spjs.utility.getDateFieldAsDateObject(‘EndDate’);
          var dateAnswer1 = spjs.utility.getDateFieldAsDateObject(‘DateAnswer1’);

          if (dateAnswer1 > startDate && dateAnswer1 < endDate) {
          return true;
          }

          else {
          alert(“Date is not range”);
          return false;
          }

          }

        • #37512
          Alexander Bautz
          Keymaster

            I’m glad you figured it out.

            Alexander

        Viewing 2 reply threads
        • You must be logged in to reply to this topic.