4

I am using the pickadate library so the user can select dates. All dates should be disabled by default. This works by adding disabled: [true].

var myPicker=$("#inputDatetime").pickadate(
    {
        format:"dd. mmmm yyyy",
        formatSubmit:"yyyy-mm-dd",
        min:dt,
        selectYears:2,
        close:"Schliessen",
        today:"Heute",
        selectMonths:!0,
        disable: [true]
    }
), picker = myPicker.pickadate("picker");

After this I am enabling some dates:

picker.set('disable', activeDays);

Now I want to be able to have blacklisted weekdays. For example all mondays and all wednesdays should always be blocked. I have this data in another variable:

var disabledDates = [1, 3];

How do I make sure the weekdays are disabled after that I enabled some specific dates?

nimrod
  • 5,595
  • 29
  • 85
  • 149

2 Answers2

1

See the code below:

var $input = $("#datepicker").pickadate({
    format: 'dd-mm-yyyy',
    formatSubmit: 'dd-mm-yyyy',
    editable: false,
    min: new Date(),
    firstDay: 0
});

var picker = $input.pickadate('picker');
picker.set("disable", [
    1,
    [2016, 5, 29],
    [2016, 6, 9],
    [2016, 8, 8]
]);

picker.set("enable", [
    [2016, 5, 19],
    [2016, 5, 26]
]);

You can test it here: http://jsfiddle.net/2j4f9dh8/2/

Paulo Prestes
  • 484
  • 2
  • 8
0

You can use get method to get already listed enabled and disabled dates and just push weekdays indexes you want to disable:

picker.set('disable', activeDays);
var disabledDates = picker.get('disable').push([1, 3]);
picker.set('enable', true); // Enable all days to be sure we will not flip  disabled/enabled states
picker.set('disable', disabledDates);

Don't forget to enable dates before disabling them. In this case they will not flip to opposite values.

antyrat
  • 27,479
  • 9
  • 75
  • 76
  • Thanks, but this returns `TypeError: datesToDisable.map is not a function. (In 'datesToDisable.map', 'datesToDisable.map' is undefined)` – nimrod May 24 '16 at 13:05
  • @doonot do you have your page live example somewhere? – antyrat May 24 '16 at 14:08