Disable dates in pickadate-picker and refresh it

后端 未结 3 1368
囚心锁ツ
囚心锁ツ 2020-12-19 07:04

I try to disable some dates after I have initialised the Date Picker.

I am initialising the picker like this:

$( document ).ready(function() {
    $(         


        
3条回答
  •  囚心锁ツ
    2020-12-19 07:46

    Make your changes from within the success/error handlers and try to enable all the dates before disabling:

    function disableDates() {
    
        var disabledDays = [];
        var $input = $('#inputDatetime').pickadate();
        var picker = $input.pickadate('picker');
    
        $.ajax({  
            url: 'partners/getInactiveDays',
            dataType: 'json',
            async: false,
            success: function(data) {
                $.each(data.days, function(i, d) {
                    disabledDays.push(parseInt(d.Day.id));
                });
    
                picker.set('enable', true);
                picker.set('disable', disabledDays);
            },
            error: function() {
                picker.set('disable', true);
            }
        });
    }
    

提交回复
热议问题