Reputation: 4069
I'm working with the bootstrap datepicker found here http://www.eyecon.ro/bootstrap-datepicker/ and I've limited it to minViewMode = months. That part is working fine, but my problem is I need to take the selected date, find the number of days in the month they select, and return the last day of the month to the input field rather than the first day of the month. Below is the code I've tried so far, but when I try to set the value of the date input field using the last line in the on('hide') function, it is not working, so I tried using the changeDate event and it still does not work.
Does anyone know how I can set the value manually once a month has been selected?
var ending_month = $('#dpEND').datepicker(
{
format: "mm/dd/yyyy",
viewMode: "years",
minViewMode: "months"
})
.on('changeDate',function(ev)
{
if(ev.viewMode=='months')
{
var endingDate = new Date(ev.date);
var endingMonth = endingDate.getMonth();
var endingYear = endingDate.getFullYear();
var endingDay = getDaysInMonth(endingMonth, endingYear);
endingDate = new Date(endingYear,endingMonth,endingDay);
ending_month.setValue(endingDate);
$('#dpEND').datepicker('hide');
}
});
I keep getting an error in the console stating that object ending_month does not have a method setValue, althought the docs say it does.
UPDATE
I've got it working. I needed to use $('#dpEND').datepicker('setValue',value);
instead of ending_month.setValue();
Upvotes: 0
Views: 7967
Reputation: 4069
I've got it working. I needed to use $('#dpEND').datepicker('setValue',value);
instead of ending_month.setValue();
Upvotes: 1