Classic dffs – block out dates on date field calendar

Forums Classic DFFS Classic dffs – block out dates on date field calendar

Viewing 5 reply threads
  • Author
    Posts
    • #37422
      Leon
      Participant

      Hi Alex,

      Hoping you can help me with a solution. I would like to block out dates available to be chosen from a date field calendar. For instance a due date field I would like the use to not be able to choose anything within 5 days or even business days if possible.. any suggestions? I have not had any luck searching for this type of solution.

      Thank you

    • #37423
      Alexander Bautz
      Keymaster

      There is unfortunately no function to block the selection of the dates, but you can run a validation after the user has picked the date by adding some custom js and a rule.

      Add this to your custom js:

      function validateDateField() {
          var dateFieldInternalName = "DateColumn1";
          jQuery(".customDateValidation").remove();
          var today = new Date();
          var date = spjs.utility.getDateFieldAsDateObject(dateFieldInternalName);
          var requiredDateOffset = 6;
          var diffDays = (date - today) / (24*60*60*1000);
          if (diffDays < requiredDateOffset) {
              jQuery("#dffs_"+dateFieldInternalName+" td.ms-formbody").append("<div class='customDateValidation' style='color:red;'>The date must be atleast <strong>"+requiredDateOffset+"</strong> in the future.</div>");
              jQuery("#dffs_"+dateFieldInternalName+" input").val("");
          }
      }
      

      Change “DateColumn1” to match your date field internal name.

      Now add a rule that triggers on “is changed” on your date field and add the name of the function to the “Run these functions / evaluate these rules” field like this:

      validateDateField
      

      When a selection is made in the field, this code checks if the value selected is 6 days in the future and shows a message and clears the value if it is not at least 6 days ahead.

      Alexander

      • This reply was modified 6 months ago by Alexander Bautz. Reason: Fixed code snippet format
    • #37425
      Leon
      Participant

      Thank you Alex!

    • #37837
      Leon
      Participant

      Alex,

      I am not being asked to change it from saying choose a date x days in the future to displaying the earliest date, but I am having issues. Hoping you can assist.

      I added a variable line
      var reqDate = today.setDate(today.getDate() + 6);

      I was hoping this would display a date 6 days from today (example 8/1/24) but it is not working as expected. I also tried adding “/
      24*60*60*1000” and “/ 86400000” with no luck.
      Any suggestions? Also is it possible to have the date offset be calendar days?

      • #37839
        Alexander Bautz
        Keymaster

        No problem, use something like this

        var today = new Date();
        var datePlus6 = new Date(today.setDate(today.getDate() + 6));
        spjs.utility.setDateFieldFromDateObject("Your_date_column_fin", datePlus6);
        

        Alexander

    • #37841
      Leon
      Participant

      Thanks Alex! This worked perfectly.

      Is there any way to have the offset go by business days (Monday-Friday)?

    • #37842
      Alexander Bautz
      Keymaster

      You can use something like this:

      var today = new Date();
      var datePlusOffset = null;
      var offset = 6; // The offset number of business days
      var ticker = 0;
      while(ticker < offset){
          datePlusOffset = new Date(today.setDate(today.getDate() + 1));
          let day = datePlusOffset.getDay();
          if(day !== 6 && day !== 0){
              ticker += 1;
          }
      }
      spjs.utility.setDateFieldFromDateObject("DateColumn1", datePlusOffset);
      

      Alexander

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