You could put this script in an HTML field in the form or maybe add to your site scripts.
Last active
March 4, 2024 21:41
-
-
Save darinronne/3a06538d37628abddb5f87516cd5b84e to your computer and use it in GitHub Desktop.
Gravity Forms disable days
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gform.addFilter( 'gform_datepicker_options_pre_init', function( optionsObj, formId, fieldId ) { | |
// Form ID and Field ID | |
if ( formId == 2 && fieldId == 6 ) { | |
optionsObj.firstDay = 0; | |
optionsObj.beforeShowDay = function(date) { | |
let dayOfWeek = date.getDay(); | |
let today = new Date(); | |
// let today = new Date('2024-03-09T15:00:00'); | |
// If the current day is Saturday, | |
// then increment 'today' by two days so that the following Monday is disabled. | |
if (today.getDay() == 6) { | |
today.setDate(today.getDate() + 2); | |
} | |
// If the current day is Sunday, | |
// then increment 'today' by one day so that the following Monday is disabled. | |
else if (today.getDay() == 0) { | |
today.setDate(today.getDate() +1); | |
} | |
// If Mon-Fri and the current hour is equal to or greater than 15 (3PM) | |
else if ( today.getHours() >= 15 ) { | |
// If current day is Friday, increment 'today' by three days so that the following Monday is disabled. | |
if (today.getDay() == 5) { | |
today.setDate(today.getDate() + 3); | |
// Else Mon-Thur, increment 'today' by one day so that the following day is disabled. | |
} else { | |
today.setDate(today.getDate() + 1); | |
} | |
} | |
// Enabled days: | |
// NOT Sunday | |
// NOT Saturday | |
// Days after 'today' | |
return [(dayOfWeek != 0) && (dayOfWeek != 6) && (date > today), '']; | |
}; | |
} | |
return optionsObj; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment