I have two datepicker inputs and I'm trying to automatically open the second one after a date is selected in the first. As of now, the datebox opens and then promptly closes. I can do it just fine outside of my knockout.js viewmodel without the datebox closing, but the problem is I want the second datebox to open only if the first one has a valid date.
This works just fine outside of my viewmodel, as I mentioned above, however it doesn't account for any errors with the start date.
$("#start_date_input").datepicker('option',"onClose", function() {
$( "#start_date_input" ).datepicker( "show" );
});
This is where I'd like the second datepicker to be triggered
self.startDate.subscribe(function(){
var startDateErrors = ko.validation.group(self.startDateValidation);
var endDateErrors = ko.validation.group(self.endDateValidation);
if(startDateErrors().length == 0 && endDateErrors().length == 0){
populateList();
}
else if(startDateErrors().length == 0){ //if a valid start date is selected, show the end date
$("#end_date_input").datepicker("show");
}
});
As soon as I select a start date, the end date picker shows and immediately disappears. The cursor is still in the end date input box and flashing. Any idea what is causing it to close?
I tried adding $("end_date_input").datepicker({autoclose: false});
but that didn't do anything.