Disable + one day of the week Datepicker

Asked

Viewed 87 times

2

my code below disables the days I register (holidays) and disables Saturday and Sunday. I also need now disable the Friday, but caught and did not work rsrs...

<script>
var nomersw = 'inicio_gozo_ferias_coletivas_atibaia';
var bankHoliDaysrsw = ["09-05-2019", "09-06-2019", "10-10-2019", "10-11-2019", "10-31-2019", "11-01-2019", "11-13-2019", "11-14-2019", "11-15-2019", "12-23-2019", "12-24-2019", "12-25-2019", "12-30-2019", "12-31-2019", "01-01-2020", "02-24-2020", "02-25-2020", "04-08-2020", "04-09-2020", "04-10-2020", "04-20-2020", "04-21-2020", "04-29-2020", "04-30-2020", "05-01-2020", "06-09-2020", "06-10-2020", "06-11-2020", "06-22-2020", "06-23-2020", "06-24-2020", "07-07-2020", "07-08-2020", "07-09-2020", "09-07-2020", "10-12-2020", "11-02-2020", "12-23-2020", "12-24-2020", "12-25-2020", "12-30-2020", "12-31-2020", "01-01-2021"]

if(jQuery('input[name="'+nomersw+'"]')){
    jQuery('input[name="'+nomersw+'"]').datepicker('destroy');  
    function disableDates(date) {
        var dt = jQuery.datepicker.formatDate('mm-dd-yy', date);
        var noWeekend = jQuery.datepicker.noWeekends(date);
        return noWeekend[0] ? ((jQuery.inArray(dt, bankHoliDaysrsw) < 0) ? [true] : [false]) : noWeekend;
    }
    jQuery('input[name="'+nomersw+'"]').datepicker({    
        numberOfMonths:2, 
        dateFormat: 'dd/mm/yy', 
        beforeShowDay: disableDates
    });
}
</script>

Any colleague has any idea how this code would look, disabling adding to disable Friday?

1 answer

2

You can use the method getDay() to pick up the day of the week if it is 5 (Friday) you ignore the day too:

    function disableDates(date) {
        if (date.getDay() === 5)
            return false;

        var dt = jQuery.datepicker.formatDate('mm-dd-yy', date);
        var noWeekend = jQuery.datepicker.noWeekends(date);
        return noWeekend[0] ? ((jQuery.inArray(dt, bankHoliDaysrsw) < 0) ? [true] : [false]) : noWeekend;
    }
  • Colleague, thank you very much. It worked perfectly, only change according to the day to disable another day right (4 = the fifth, 3 = the fourth, etc?

  • If I want to disable two days, example Wednesday (3) and Thursday (4), how would be? I tested, but did not roll : (

  • @Thiagosales I believe it is only to increment if: if(date.getDay() == 3 || date.getDay === 4) Return false;

  • @m-bertolazo Colleague, I tested, reversed, changed the code and destroyed the kkkkk form by applying the changed code if(date.getDay() === 3 || date.getDay === 4) disabled only the first day (3)

  • I got it right : ) Thank you...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.