skip to Main Content

I would like to be able to deactivate days + weekday numbers 1 to 7.

calendar.flatpickr({
                        disable: dateUnvailableCalendar,
                        minDate: "today",
                        onChange: function (selectedDates, dateStr) {
                            calendarHandleChange(dateStr);
                        }
                    });

This is what I have already done. this disable days i send in an array.
now i wish i could disable day number 5 and 7 of every week of the whole year.
Do you know how I can do this please?

Thank you for help.

2

Answers


  1. Chosen as BEST ANSWER

    I found a solution however in dynamic mode it does not work. Here is the solution:

    disable: [
                                function(date) {
                                    return (date.getDay() === 0 || date.getDay() === 6);
                                },
                                {
                                    'from': '2023-03-06',
                                    'to' : '2023-03-13'
                                },
                                {
                                    'from': '2023-03-21',
                                    'to' : '2023-03-21'
                                }
                            ],
    

    do you have any idea how i can convert my json to look like my example? I tried the JSON.stringify but the json comes out with [] and it is not interpreted. Thank you.

    console.log(dateUnvailableCalendar);

    array


  2. flatpickr("#myDatePicker", {
      disable: [
        function(date) {
          // saturdays
          return date.getDay() === 6;
        },
        function(date) {
          // sundays
          return date.getDay() === 0;
        }
      ]
    });
    

    Disabling range of dates

    Disabling specific dates

    To disable dates that are in an array:

    var dates = ["2025-01-30", "2025-02-21", "2025-03-08", new Date(2025, 4, 9) ];
    flatpickr("#myDatePicker", {
      disable: dates
    });
    

    In your case, for specific dates and Saturdays:
    I suppose that in ‘dateUnavailableCalendar’ you will have an array of dates.

    flatpickr("#myDatePicker", {
      disable: [
        function(date) {
          return date.getDay() === 6;
        },
        dateUnavailableCalendar
        
      ]
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search