Reputation: 65
trying to disable some specific dates in materializeCSS datepicker, but not getting any way to implement this feature.
Upvotes: 1
Views: 3767
Reputation: 89
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({
// ... some your settings
format : 'mm/dd/yyyy',
onDraw : function() {disableDates(iptalTarih);}
onOpen : function() {setTimeout(function() {disableDates(iptalTarih)},300)},
})
Upvotes: 0
Reputation: 613
JavaScript Vanilla Disable one or more specific date in Materialize - Date picker
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
}
}
Upvotes: 0
Reputation: 21
This is an example of how to receive a JSON of allowed dates and show them in the timepicker.
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);
});
Upvotes: 2
Reputation: 1
$('.datepicker').pickadate({
disable: [
{from: [2017,5,12], to: [2017,5,12]}
]
})
Upvotes: 0
Reputation: 4026
Materializecss datepicker is just wrapper for 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
Upvotes: 2