File tree Expand file tree Collapse file tree 3 files changed +29
-9
lines changed
src/BootstrapBlazor/Components/DateTimePicker Expand file tree Collapse file tree 3 files changed +29
-9
lines changed Original file line number Diff line number Diff line change @@ -539,7 +539,12 @@ private async Task UpdateDisabledDaysCache(bool force)
539539 }
540540 }
541541
542- private bool IsDisableDay ( DateTime val )
542+ /// <summary>
543+ /// 判定当前日期是否为禁用日期
544+ /// </summary>
545+ /// <param name="val"></param>
546+ /// <returns></returns>
547+ public bool IsDisableDay ( DateTime val )
543548 {
544549 bool ret = false ;
545550 if ( _monthDisabledDaysCache . TryGetValue ( $ "{ StartDate : yyyyMMdd} -{ EndDate : yyyyMMdd} ", out var disabledDays ) )
Original file line number Diff line number Diff line change 1818 ShowLunar =" ShowLunar" ShowSolarTerm =" ShowSolarTerm" ShowFestivals =" ShowFestivals" ShowHolidays =" ShowHolidays"
1919 OnConfirm =" OnConfirm" OnClear =" OnClear" MinValue =" MinValue" MaxValue =" MaxValue"
2020 AutoClose =" AutoClose" ViewMode =" ViewMode" DayTemplate =" DayTemplate!" DayDisabledTemplate =" DayDisabledTemplate!"
21- OnGetMonthDisabledDaysCallback =" OnGetMonthDisabledDaysCallback!"
21+ OnGetMonthDisabledDaysCallback =" OnGetMonthDisabledDaysCallback!" @ref = " _datePickerBody "
2222 EnableGetMonthDisabledDaysCache =" EnableGetMonthDisabledDaysCache" >
2323 @ChildContent
2424 </DatePickerBody >
Original file line number Diff line number Diff line change @@ -234,6 +234,8 @@ public string? Format
234234
235235 private DateTime SelectedValue { get ; set ; }
236236
237+ private DatePickerBody ? _datePickerBody = default ;
238+
237239 /// <summary>
238240 /// <inheritdoc/>
239241 /// </summary>
@@ -317,14 +319,27 @@ protected override string FormatValueAsString(TValue value)
317319 d = v2 . DateTime ;
318320 }
319321
320- if ( d . HasValue && MinValueToToday ( d . Value ) )
321- {
322- d = DateTime . Today ;
323- }
324-
325- if ( d . HasValue && ! MinValueToEmpty ( d . Value ) )
322+ if ( d . HasValue )
326323 {
327- ret = d . Value . ToString ( ViewMode == DatePickerViewMode . DateTime ? DateTimeFormat : DateFormat ) ;
324+ if ( MinValueToToday ( d . Value ) )
325+ {
326+ d = DateTime . Today ;
327+ }
328+
329+ if ( _datePickerBody != null )
330+ {
331+ var isDisabled = _datePickerBody . IsDisableDay ( d . Value ) ;
332+ if ( isDisabled )
333+ {
334+ d = DateTime . MinValue ;
335+ }
336+
337+ var isEmpty = MinValueToEmpty ( d . Value ) ;
338+ if ( ! isEmpty )
339+ {
340+ ret = d . Value . ToString ( ViewMode == DatePickerViewMode . DateTime ? DateTimeFormat : DateFormat ) ;
341+ }
342+ }
328343 }
329344 return ret ;
330345 }
You can’t perform that action at this time.
0 commit comments