Disable dates in pickadate-picker and refresh it

后端 未结 3 1387
囚心锁ツ
囚心锁ツ 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:53

    I couldn't let this go, so I've tested it quite extensively. In the end of the day, it works like it should. There is no need to stop, start or render it. The issue must be with your json-data, or the data in general (dates, ints).

    I created two examples in jsfiddle, demonstrating that it does indeed work with the type of data you seem to be expecting.

    I would advise you to log data.days, d.Day.id and finally disabledDays to console to check what they actually contain. If nothing else I hope you can have my fiddle examples as reference.

    A note about the code though. The first time you initialize the picker you can assign it to a variable:

    var myvar = $('#inputDatetime').pickadate({
        format: 'dd. mmmm yyyy',
        formatSubmit: 'yyyy-mm-dd',
        min: dt,
        selectYears: 2,
        selectMonths: true
    });
    

    And then, when you need to get this instance, you just do:

    var picker = myvar.pickadate('picker');
    picker.set('disable', [1,7]); //disables all saturdays & sundays
    

    No need to reinitialize it in other words.

    Also, a last note. Setting disabled dates doesn't clear previously set dates. You just keep adding to the collection of disabled dates, and when you use days you only have 1-7 to work with before everything is disabled.

提交回复
热议问题