简体   繁体   English

如何在MaterialiseCSS datepicker中禁用特定日期

[英]How to Disable Specific Dates in MaterializeCSS datepicker

尝试禁用materializeCSS datepicker中的某些特定日期,但没有任何方法来实现此功能。

Materializecss datepicker is just wrapper for pickadate.js Materializecss datepicker只是pickadate.js的包装器

So you can do in that way: 所以你可以这样做:

$('.datepicker').pickadate({
  disable: [
    new Date(2015,3,13),
    new Date(2015,3,29)
  ]
})

You can read more about it here: http://amsul.ca/pickadate.js/date/#disable-dates 你可以在这里阅读更多相关信息: http//amsul.ca/pickadate.js/date/#disable-dates

This is an example of how to receive a JSON of allowed dates and show them in the timepicker. 这是如何接收允许日期的JSON并在时间戳中显示它们的示例。

var $input = $('.datepicker').pickadate()
var picker = $input.pickadate('picker');

picker.stop();
picker.start();

$.get("/dates",
    { id: this.value },
    function(data) {

        let value=[];
        $.each(data, function(key, element) {
            let fecha=new Date(element.date);
            value.push([fecha.getFullYear(),
                fecha.getMonth(),
                fecha.getDate()+1]);
        });
        picker.set('disable', value);
        picker.set('disable', 'flip');
        picker.open(false);

    });
$('.datepicker').pickadate({
  disable: [
    {from: [2017,5,12], to: [2017,5,12]}
  ]
})

JavaScript Vanilla Disable one or more specific date in Materialize - Date picker JavaScript Vanilla 在Materialise - 日期选择器中禁用一个或多个特定日期

 disableDayFn:function (date) { let disableListDate = [new Date('2018,12,5').toDateString(),new Date('2018,12,6').toDateString()]; if(disableListDate.includes(date.toDateString())) { return true }else{ return false } } 

var iptalTarih = ['04/18/2019', '05/20/2019']; // Your Dates Here in 'mm/dd/yyyy'

function disableDates(iptalTarih) {
    for (var i = 0; i < iptalTarih.length; i++) {
            var 
            fullDisabledDate    = new Date(iptalTarih[i]),
            getDisabledMonth    = fullDisabledDate.getMonth(),
            getDisabledDay      = fullDisabledDate.getDate(),
            getDisabledYear     = fullDisabledDate.getFullYear();

            $('.datepicker-modal.open').find('button.datepicker-day-button[data-year="'+getDisabledYear+'"][data-month="'+getDisabledMonth+'"][data-day="'+getDisabledDay+'"]').parent('td').addClass('is-disabled');

    }
}

and where initialize your datepicker : 以及初始化datepicker的地方:

    $('.datepicker').datepicker({
        // ... some your settings
        format          : 'mm/dd/yyyy',
        onDraw          : function() {disableDates(iptalTarih);}
        onOpen          : function() {setTimeout(function() {disableDates(iptalTarih)},300)},
    })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM