How to disable specific dates for each years in a date picker

Hi,
I want to disable french public holidays in my datepicker. So, I used the following and it’s working. But, to avoid a manual modifying every year I want to disable these specific dates for every years coming. Does anyone know how to do it ?

Thanks a lot

<script>
gform.addFilter( 'gform_datepicker_options_pre_init', function( optionsObj, formId, fieldId ) {
    if ( formId == 1 && fieldId == 24 ) {
        var disabledDays = ['04/21/2025', '05/01/2025', '05/08/2025', '05/29/2025', '07/14/2025', '08/15/2025', '11/01/2025', '11/11/2025', '12/25/2025'];
        optionsObj.beforeShowDay = function(date) {
            var checkdate = jQuery.datepicker.formatDate('mm/dd/yy', date);
            return [disabledDays.indexOf(checkdate) == -1];
        };
    }
    return optionsObj;
});
</script>

Hi Comptoir,

To disable French public holidays from the datepicker, please use the following code, which will automatically disable them for all future years, eliminating the need for manual updates each year.

jQuery(document).ready(function ($) {
  gform.addFilter("gform_datepicker_options_pre_init", function (optionsObj, formId, fieldId) {
    // Update your form ID and field ID here
    if (formId == 1 && fieldId == 24) {
      optionsObj.beforeShowDay = function (date) {
        var disabledDays = ["04/21", "05/01", "05/08", "05/29", "07/14", "08/15", "11/01", "11/11", "12/25"];

        var checkdate = jQuery.datepicker.formatDate("mm/dd", date);

        return [disabledDays.indexOf(checkdate) == -1];
      };
    }

    return optionsObj;
  });
});

Preview:

disabled-public-holidays

Give it a try, and let me know how that goes! :smile:

2 Likes

Hi, thank you very much, it’s working.
But now I want disable french public holidays, weekends and also the 2 next day, so I did this (but it’s not working). Each thing is working separetly but not together (I do not know how to code jquery…)

<script>
gform.addFilter( 'gform_datepicker_options_pre_init', function( optionsObj, formId, fieldId ) {
    if ( formId == 1 && fieldId == 24 ) {
        /** sauf week-end **/
        optionsObj.firstDay = 1;
        optionsObj.beforeShowDay = jQuery.datepicker.noWeekends;
        /** sauf 2j avant **/
        optionsObj.minDate = 2;
        /** sauf jours feries **/
        optionsObj.beforeShowDay = function (date) {
        var disabledDays = ["04/21", "05/01", "05/08", "05/29", "07/14", "08/15", "11/01", "11/11", "12/25"];
        var checkdate = jQuery.datepicker.formatDate("mm/dd", date);
        return [disabledDays.indexOf(checkdate) == -1];
      };
    }
    return optionsObj;
});
</script>```
Culd you help me please :)

Hi again,

Could you please try the following code and let me know how it goes?

jQuery(document).ready(function($) {
    gform.addFilter('gform_datepicker_options_pre_init', function(optionsObj, formId, fieldId) {
        if (formId == 1 && fieldId == 24) {
            optionsObj.firstDay = 1;
            optionsObj.minDate = 2;
            
            optionsObj.beforeShowDay = function(date) {
                var disabledDays = ["04/21", "05/01", "05/08", "05/29", "07/14", "08/15", "11/01", "11/11", "12/25"];
                var checkdate = jQuery.datepicker.formatDate("mm/dd", date);
                
                // Check both weekends and holidays
                var isWeekend = jQuery.datepicker.noWeekends(date)[0] === false;
                var isHoliday = disabledDays.indexOf(checkdate) !== -1;
                
                return [!isWeekend && !isHoliday];
            };
        }
        return optionsObj;
    });
});

Preview:

Awesome ! It’s working, thank you very much :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.