I have a calendar function that gets and sets a chosen start date, which works ok.
However when navigating away from the page and back to the previous page. How do I preserve the calendar on the day/month chosen when its beyond the present month. e.g. We are now in January, but if I navigate away to feb or march and navigate back, it defaults back to january.
Here is my code
var fullDate = new Date();
var newdate = new Date(fullDate);
newdate.setDate(newdate.getDate() + 90);
$('div[data-type="datepicker-coverStartDate"]').fullCalendar({
dayClick: function(date, allDay, jsEvent, view) {
if (moment(date).isSameOrAfter(moment().startOf('day'))) {
$('.fc-state-highlight').removeClass("fc-state-highlight");
$(this).addClass("fc-state-highlight");
$('div[data-type="datepicker-coverStartDate"]').datepicker("setDate", $('#inpCoverStartDateActual').attr("value"));
onDatePickerChanged('coverStartDate', date.toLocaleDateString("en-gb"));
}
if (date >= newdate) {
$(this).removeClass("fc-state-highlight");
$(this).addClass("fc-state-disabled");
}
}
and html input and calendar field
<input type="hidden" id="inpCoverStartDateActual"
v-bind:value="coverStartDate"
name="@(NameOf<TellUsAboutYourHomeViewModel>.Full(basePropertyName, m => m.CoverStartDate))"
value="@(Model.CoverStartDate == DateTime.MinValue ? "" : Model.CoverStartDate.ToString(" dd/MM/yyyy"))" />
<div id="inpCoverStartDate"
value="@(Model.CoverStartDate == DateTime.MinValue ? "" : Model.CoverStartDate.ToString(" dd/MM/yyyy"))"
data-type="datepicker-coverStartDate"
data-vue-data="coverStartDate"
type="text">
</div>