Reputation: 95
I am using datpicker to provide options to select the month/year only and when the month is selected, a form is submitted with the selected value.
here is the code: jquery ui datepicker with this code:
$(document).ready(function(){
$("#datepicker").datepicker( {
changeMonth: true,
changeYear: true,
showButtonPanel: false,
yearRange: "2013:2015",
onChangeMonthYear: function(dateText, inst) {
console.log($(".ui-datepicker-year :selected",$(this)).val()
+ "/" + $(".ui-datepicker-month :selected",$(this)).val());
}
});
});
but there are two situations when the number returned is wrong.
(values in console.log)
if you try to select a month lets say oct 2013, returned value is 2013/9, which is ok. now if you try to click on the arrow to go to nov 2013, again the value is 2013/9 which is wrong. similarly jumping from dec 2013 to jan 2012 returns 2013/11
if you go to the end "dec 2015", and then click the next arrow, it goes back to the beginning "jan 2013", which is ok, but then keep clicking on the next arrow, you will notice you can no longer move from "dec 2013" to "jan 2014", it moves back to "jan 2013"
any help is appreciated.
Upvotes: 0
Views: 999
Reputation: 654
onChangeMonthYear()
receives the newly selected year and month as arguments, so you can just use those directly
...
minDate: new Date(2013, 1 - 1, 1),
maxDate: new Date(2015, 12 - 1, 31),
onChangeMonthYear: function(year, month, inst) {
console.log(
year + "/" + month
);
}
Upvotes: 1