I want to disable Sundays in jQuery UI calendar.
From docs I came to know about this:--
$('#datepicker').datepicker({ minDate: 4,beforeShowDay: $.datepicker.noWeekends });
This will disable Saturdays and Sundays both. But I want to diasble only Sunday. Is there any default option for this.
开发者_StackOverflow社区Bad way to solve it
beforeShowDay take true or false as params for every day. So write a function which returns true or false based upon each day.
try this
$("#datepicker").datepicker({
beforeShowDay: function(date) {
var day = date.getDay();
return [(day != 0), ''];
}
});
Yes you can disable Saturday and Sunday, In jQuery UI datepicker.
https://codepen.io/VijayDhanvai/pen/ExjdGPb
$("#date").datepicker({
beforeShowDay: function(date) {
var day = date.getDay();
return [(day != 0 && day != 6), ''];
}
});
you can also use this code it is working for me
$("#date").datepicker({
filter: function(date, view) {
if (date.getDay() === 0 && view === 'day') {
return false; // Disable all Sundays, but still leave months/years, whose first day is a Sunday, enabled.
}
}
});
compared to the best answer, here's how to add options to the datepicker besides disabling Sundays :
$('#datepicker_fin').datepicker(
{
beforeShowDay: function(date)
{
var day = date.getDay();
return [(day != 0), ''];
},
dateFormat: 'dd-mm-yy',
changeYear: true,
maxDate: null
});
精彩评论