Reputation: 35963
I have a little problem with datepicker, I'd want that a user with arrows can only select a date between the first day of the first month and the last day of the month, but it would be dynamic because if we are in 2014 I have to see only year of 2014.
I have tried in this mode but with arrows I can go to 2012 or 2014 for example:
$('#check-in').datepicker({ dateFormat: 'dd-mm', changeYear: false, yearRange: "-0:+0", stepYears: 0 });
Upvotes: 3
Views: 26932
Reputation: 5985
Just use yearRange
like this:
datepick({yearRange: new Date().getFullYear() + ':' + new Date().getFullYear()});
Upvotes: 2
Reputation: 40038
This will work for you:
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(document).ready(function() {
var date = new Date(), y = date.getFullYear(), m = date.getMonth();
var fSDate = new Date(y, m, 1);
var fEDate = new Date(y, m + 1, 0);
$.datepicker.setDefaults({
changeMonth: false,
changeYear: false,
showOtherMonths: false,
yearRange: '-0:+0',
dateFormat: 'yy-mm-dd',
defaultDate: +0,
numberOfMonths: 1,
minDate: fSDate,
maxDate: fEDate,
showAnim: 'fadeIn',
showButtonPanel: false
});
$('#date_start').datepicker();
}); //END document.ready()
</script>
</head>
<body>
<input type="text" id="date_start">
</body>
</html>
Upvotes: 0
Reputation: 17550
Set minDate
and maxDate
like
$(function() {
var year = (new Date).getFullYear();
$( "#datepicker" ).datepicker({
minDate: new Date(year, 0, 1),
maxDate: new Date(year, 11, 31)
});
});
Upvotes: 7
Reputation: 3128
Why not mention the yearRange to be currentyear : currentyear?
You can do this: after
$(document).ready(function(){
var curyear = $("#year").text( (new Date).getFullYear() );
Inside your datepicker,
yearRange: "+curyear+":"+curyear+"
Upvotes: 0