multiDatesPicker disable certain dates on a button click

275 views Asked by At

How can I add disabled dates to a multiDatesPicker on the click of a button? I was hoping it would be as easy as this, but it this doesn't work. Any help will be very welcome.

<a href="#" onclick="javascript:addDisableDatesOnClick();">Add Disabled Dates</a>

function addDisableDatesOnClick() {
            var dateArray = ["07/10/2018", "07/11/2018"];
            $('#mdp-demo').multiDatesPicker("addDisabledDates", dateArray);
        }
1

There are 1 answers

0
Leon Gentle On

I found the answer. I had to "destroy" and re-create the multiDatesPicker.

function addDisableDatesOnClick() {
        $('#mdp-demo').multiDatesPicker('destroy');
        var today = new Date();
        var y = today.getFullYear();
        $('#mdp-demo').multiDatesPicker({
            addDates: ['07/5/' + y]
            , addDisabledDates: ['07/24/' + y]
            , numberOfMonths: [2, 3]
            , altField: '#altField'
            , defaultDate: '7/1/' + y
        });
    }