-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MudForm: Only set Validation if For is set (#5419)
MudForm: Only set Validation if For is not null
- Loading branch information
1 parent
4fcb43d
commit 83b6bcb
Showing
6 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/MudBlazor.UnitTests.Viewer/TestComponents/Form/FormAutomaticValidationTest.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
@namespace MudBlazor.UnitTests.TestComponents | ||
@using FluentValidation | ||
|
||
<MudForm Model="@Model" Validation="@(ValidationRules.ValidateValue)"> | ||
<MudTextField @bind-Value="Model.String1" For="(() => Model.String1)" /> | ||
<MudTextField @bind-Value="Model.String2" /> | ||
<MudDatePicker @bind-Date="Model.DateTime1" For="(() => Model.DateTime1)" /> | ||
<MudDatePicker @bind-Date="Model.DateTime2" /> | ||
</MudForm> | ||
|
||
@code { | ||
TestClass Model = new(); | ||
TestClassValidator ValidationRules = new(); | ||
|
||
public class TestClass | ||
{ | ||
public string String1 { get; set; } | ||
public string String2 { get; set; } | ||
public DateTime? DateTime1 { get; set; } | ||
public DateTime? DateTime2 { get; set; } | ||
} | ||
|
||
public class TestClassValidator : AbstractValidator<TestClass> | ||
{ | ||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) => | ||
{ | ||
var result = await ValidateAsync(ValidationContext<TestClass>.CreateWithOptions((TestClass)model, x => x.IncludeProperties(propertyName))); | ||
if (result.IsValid) | ||
return Array.Empty<string>(); | ||
return result.Errors.Select(e => e.ErrorMessage); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters