Home › Forums › Classic DFFS › Classic dffs – block out dates on date field calendar
- This topic has 6 replies, 2 voices, and was last updated 4 months, 3 weeks ago by Alexander Bautz.
-
AuthorPosts
-
-
January 24, 2024 at 21:21 #37422
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
-
January 25, 2024 at 16:41 #37423
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 11 months ago by Alexander Bautz. Reason: Fixed code snippet format
-
January 25, 2024 at 16:45 #37425
Thank you Alex!
-
July 26, 2024 at 17:15 #37837
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?-
July 26, 2024 at 18:28 #37839
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
-
-
July 26, 2024 at 18:53 #37841
Thanks Alex! This worked perfectly.
Is there any way to have the offset go by business days (Monday-Friday)?
-
July 26, 2024 at 21:00 #37842
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
-
-
AuthorPosts
- You must be logged in to reply to this topic.