xxxxxxxxxx
1
2
<div class='container my-5'>
3
<h2>
4
Datepickers will allow to select at least 7 days period.
5
</h2>
6
<div class='d-flex mt-5'>
7
<div class="form-outline datepicker1">
8
<input type="text" class="form-control" id="exampleDatepicker11" />
9
<label for="exampleDatepicker11" class="form-label">
10
Start date
11
</label>
12
</div>
13
<div class="form-outline datepicker2">
14
<input type="text" class="form-control" id="exampleDatepicker11" />
15
<label for="exampleDatepicker11" class="form-label">End date</label>
16
</div>
17
</div>
18
</div>
19
1
1
xxxxxxxxxx
1
const datepicker1El = document.querySelector('.datepicker1')
2
const datepicker2El = document.querySelector('.datepicker2')
3
4
const datepicker1 = new mdb.Datepicker(datepicker1El, {title: 'Select start date', disablePast:true})
5
const datepicker2 = new mdb.Datepicker(datepicker2El, {title: 'Select end date'})
6
7
datepicker1El.addEventListener('dateChange.mdb.datepicker', () => {
8
const date = new Date()
9
date.setDate(datepicker1._selectedDate.getDate() + 7)
10
datepicker2.update({min: date, startDate: date})
11
datepicker2._activeDate = date;
12
13
setTimeout(() => {
14
datepicker2.open()
15
}, 200)
16
17
const input = datepicker2El.querySelector('input')
18
let dateMonth = String(date.getMonth() + 1)
19
let dateDay = String(date.getDate())
20
21
if(dateMonth.length === 1) {
22
dateMonth = '0' + dateMonth
23
}
24
if(dateDay.length === 1) {
25
dateDay = '0' + dateDay
26
}
27
input.classList.add('active')
28
input.value = `${dateDay}/${dateMonth}/${date.getFullYear()}`
29
})
30
31
32
Console errors: 0