Disable Sundays and past dates in the dropdown calendar field [RESOLVED]

Hi all,

I know this is possible to do, but am kind of stumped at the moment.

I have a website and want to disable Sundays because we are closed Sundays. I also don’t want anyone to accidently fill out a date that’s already happened.

Here’s my form: Book Online | Express Junk Removal The calendar dropdown shows up when you select Book Service on the question “I would like to”.

I am not sure if this would be possible to code yourself as I am not a developer. However the Gravity Wiz Limit Dates perk does the kind of thing you are talking about: Gravity Forms Limit Dates | Gravity Perks by Gravity Wiz

1 Like

Hi Ryan. The Gravity Wiz Perk to Limit Dates is the no-code way to accomplish this. However, if you don’t mind a little JavaScript, add an HTML field to your form and use the gform_datepicker_options_pre_init filter to prevent Sundays and all past days from being selectable in the datepicker. Here is how you configure the script:

gform.addFilter( 'gform_datepicker_options_pre_init', function( optionsObj, formId, fieldId ) {
    if ( formId == 1 && fieldId == 24 ) {
        optionsObj.firstDay = 1;
        optionsObj.beforeShowDay = function(date) {
            var day = date.getDay();
            var today = new Date();
            today.setHours(0,0,0,0); // Set the time to midnight to ignore the time component
            return [(day != 0) && (date >= today), ''];
    return optionsObj;

Modify the Form ID from 1 and the field ID from 24 to match your form ID and datepicker field ID. Then add an HTML field to the form and paste that script in. That will prevent Sundays from being selectable in your form. If you have any other questions, please let us know.

1 Like

Thanks! Got it working!

1 Like