Skip to content

Commit 1438f19

Browse files
committed
Follow-up fix to datepicker I forgot to push
1 parent 7f774f4 commit 1438f19

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

js/src/datepicker.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,30 @@ class Datepicker extends BaseComponent {
193193
if (this._isInput && this._element.value) {
194194
this._parseInputValue()
195195
}
196+
197+
// Populate input/display with preselected dates
198+
this._updateDisplayWithSelectedDates()
199+
}
200+
201+
_updateDisplayWithSelectedDates() {
202+
const { selectedDates } = this._config
203+
if (!selectedDates || selectedDates.length === 0) {
204+
return
205+
}
206+
207+
const formattedDate = this._formatDateForInput(selectedDates)
208+
209+
if (this._isInput) {
210+
this._element.value = formattedDate
211+
}
212+
213+
if (this._boundInput) {
214+
this._boundInput.value = selectedDates.join(',')
215+
}
216+
217+
if (this._displayElement) {
218+
this._displayElement.textContent = formattedDate
219+
}
196220
}
197221

198222
_resolvePositionElement() {
@@ -309,6 +333,13 @@ class Datepicker extends BaseComponent {
309333
}
310334
}
311335

336+
// Navigate to the month of the first selected date
337+
if (this._config.selectedDates.length > 0) {
338+
const firstDate = this._parseDate(this._config.selectedDates[0])
339+
calendarOptions.selectedMonth = firstDate.getMonth()
340+
calendarOptions.selectedYear = firstDate.getFullYear()
341+
}
342+
312343
if (this._config.dateMin) {
313344
calendarOptions.dateMin = this._config.dateMin
314345
}

0 commit comments

Comments
 (0)