› Forums › Classic DFFS › Classic dffs – block out dates on date field calendar
- This topic has 2 replies, 2 voices, and was last updated 3 months ago by Leon.
-
AuthorPosts
-
-
January 24, 2024 at 21:21 #37422LeonParticipant
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 #37423Alexander BautzKeymaster
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 3 months ago by Alexander Bautz. Reason: Fixed code snippet format
-
January 25, 2024 at 16:45 #37425LeonParticipant
Thank you Alex!
-
-
AuthorPosts
- You must be logged in to reply to this topic.