]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Follow-up fix to datepicker I forgot to push
authorMark Otto <markdotto@gmail.com>
Tue, 6 Jan 2026 06:46:05 +0000 (22:46 -0800)
committerMark Otto <markdotto@gmail.com>
Fri, 9 Jan 2026 04:14:09 +0000 (20:14 -0800)
js/src/datepicker.js

index 03821e9746671c406e45fbe3bce70ea19f58ad9f..11085b5c3e1d585bc35909b8f680996908e6789d 100644 (file)
@@ -193,6 +193,30 @@ class Datepicker extends BaseComponent {
     if (this._isInput && this._element.value) {
       this._parseInputValue()
     }
+
+    // Populate input/display with preselected dates
+    this._updateDisplayWithSelectedDates()
+  }
+
+  _updateDisplayWithSelectedDates() {
+    const { selectedDates } = this._config
+    if (!selectedDates || selectedDates.length === 0) {
+      return
+    }
+
+    const formattedDate = this._formatDateForInput(selectedDates)
+
+    if (this._isInput) {
+      this._element.value = formattedDate
+    }
+
+    if (this._boundInput) {
+      this._boundInput.value = selectedDates.join(',')
+    }
+
+    if (this._displayElement) {
+      this._displayElement.textContent = formattedDate
+    }
   }
 
   _resolvePositionElement() {
@@ -309,6 +333,13 @@ class Datepicker extends BaseComponent {
       }
     }
 
+    // Navigate to the month of the first selected date
+    if (this._config.selectedDates.length > 0) {
+      const firstDate = this._parseDate(this._config.selectedDates[0])
+      calendarOptions.selectedMonth = firstDate.getMonth()
+      calendarOptions.selectedYear = firstDate.getFullYear()
+    }
+
     if (this._config.dateMin) {
       calendarOptions.dateMin = this._config.dateMin
     }