Skip to content

Commit 3218d18

Browse files
committed
refactor: 支持 DateTimeRangeValue 合规性检查
1 parent 286e9cf commit 3218d18

File tree

2 files changed

+5
-22
lines changed

2 files changed

+5
-22
lines changed

src/BootstrapBlazor/Components/DateTimeRange/DateTimeRange.razor.cs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,6 @@ public bool AllowNull
256256
[NotNull]
257257
private IStringLocalizer<DateTimeRange>? Localizer { get; set; }
258258

259-
[Inject]
260-
[NotNull]
261-
private IStringLocalizerFactory? LocalizerFactory { get; set; }
262-
263259
[Inject]
264260
[NotNull]
265261
private IIconTheme? IconTheme { get; set; }
@@ -280,24 +276,7 @@ protected override void OnInitialized()
280276
{
281277
base.OnInitialized();
282278

283-
if (FieldIdentifier != null)
284-
{
285-
var pi = FieldIdentifier.Value.Model.GetType().GetPropertyByName(FieldIdentifier.Value.FieldName);
286-
if (pi != null)
287-
{
288-
var required = pi.GetCustomAttribute<RequiredAttribute>(true);
289-
if (required != null)
290-
{
291-
Rules.Add(new DateTimeRangeRequiredValidator()
292-
{
293-
LocalizerFactory = LocalizerFactory,
294-
ErrorMessage = required.ErrorMessage,
295-
AllowEmptyString = required.AllowEmptyStrings
296-
});
297-
}
298-
}
299-
}
300-
279+
AddRequiredValidator();
301280
_showLeftButtons = RenderMode == DateTimeRangeRenderMode.Single;
302281
}
303282

src/BootstrapBlazor/Validators/RequiredValidator.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ public override void Validate(object? propertyValue, ValidationContext context,
7575
results.Add(new ValidationResult(errorMessage, memberNames));
7676
}
7777
}
78+
else if (propertyValue is DateTimeRangeValue dv && dv is { NullStart: null, NullEnd: null })
79+
{
80+
results.Add(new ValidationResult(errorMessage, memberNames));
81+
}
7882
}
7983

8084
/// <summary>

0 commit comments

Comments
 (0)