Reputation: 2003
I need to have a datepicker calender with Sundays and days that has been past be disabled.
Currently I am using this code which I found here in Stackoverflow.
<script>
$( function() {
$("#datepicker").datepicker({
beforeShowDay: function(date) {
var day = date.getDay();
return [(day != 0), ''];
}
});
} );
</script>
This does disable the Sundays which is exactly what I want. But how do I disable past dates as well?
From reading the other similar questions, I believe it should be 'mindate' that I should use, but I don't know how to write it with the following code above. Please do teach me. Thank you.
Upvotes: 0
Views: 803
Reputation: 282
Try this :
$( "#noSunday" ).datepicker({
beforeShowDay: noSunday,
minDate: 0
});
function noSunday(date){
var day = date.getDay();
return [(day > 0), ''];
};
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/mint-choc/jquery-ui.css" rel="stylesheet"/>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.0/jquery-ui.js">
</script>
<input id="noSunday" type="text">
Upvotes: 1
Reputation: 2708
Check this code :
$( function() {
$("#datepicker").datepicker({
minDate: new Date(),
beforeShowDay: function(date) {
var day = date.getDay();
return [(day != 0), ''];
}
});
} );
Upvotes: 1