问题
i have 2 calendars. So based on selection of first calendar, 2nd calendar value is been set. Now if the first calendar date is today date then the second calendar date starts from the todays date. But i want the second calendar date to set to an year from the selected date. For example, if i select first calendar date as 03/07/2020 the second calendar date must starts from 03/07/2021. Also after entering date if i clear the date and come out, it again sets back to the current date. How can i remove the current date setting when i clear the input field.
DEMO: DEMO
TS:
ngAfterViewInit() {
$('.effectiveOnlyDate').datetimepicker(
{ format: 'L' }).on('dp.change', (e) => {
const date = e.date.format('L');
this.date = date;
});
$('.onlyDate').datetimepicker(
{ format: 'L' }).on('dp.change', (e) => {
const date = e.date.format('L');
this.date = date;
});
$('.onlyDate').datetimepicker({
useCurrent: false //Important! See issue #1075
});
$(".effectiveOnlyDate").on("dp.change", (e) => {
const date = e.date.format('L');
this.date = date;
$('.onlyDate').data("DateTimePicker").minDate(e.date);
});
$(".onlyDate").on("dp.change", (e) => {
const date = e.date.format('L');
this.date = date;
$('.effectiveOnlyDate').data("DateTimePicker")
});
}
回答1:
I solved this by taking the selected date and adding one year to it.
$(".effectiveDate").on("dp.change", (e) => {
if (e.date) {
const date = e.date.format('L');
this.date = date;
this.datevar = e.date._d
this.datevar.setFullYear(this.datevar.getFullYear() + 1);
this.datevar;
} else {
this.date = null;
}
$('.expirationDate').data("DateTimePicker").minDate(this.datevar);
});
来源:https://stackoverflow.com/questions/60580834/how-to-set-the-calendar-to-one-year-from-the-selected-date-using-angular8-with-b