File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments