-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Open
Labels
Pillar: Technical DebtPriority:2Work that is important, but not critical for the releaseWork that is important, but not critical for the releasearea-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.This issue describes a behavior which is not expected - a bug.feature-blazor-form-validationThis issue is related to forms validation in BlazorThis issue is related to forms validation in Blazorhelp candidateIndicates that the issues may be a good fit for community to help with. Requires work from eng. teamIndicates that the issues may be a good fit for community to help with. Requires work from eng. team
Milestone
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
Adding validation errors using the below ValidationMessageStore.Add method triggers a warning when nullable annotations are enabled for the project, and the property referenced in the accessor parameter has a nullable type.
aspnetcore/src/Components/Forms/src/ValidationMessageStore.cs
Lines 38 to 39 in 2f68ef8
| public void Add(Expression<Func<object>> accessor, string message) | |
| => Add(FieldIdentifier.Create(accessor), message); |
Expected Behavior
No warnings are displayed for properties with nullable type.
Steps To Reproduce
The following code shows how the warning message is triggered:
private TestModel model = new();
private class TestModel
{
public string? Text { get; set; }
}
private void ManualValidation()
{
var messageStore = new ValidationMessageStore(editContext);
if (true /* External validation rule */)
{
messageStore?.Add(() => model.Text, "This value is not valid");
// ^^^^^^^^^^ <-- Warning triggered here
}
}Exceptions (if any)
No response
.NET Version
6.0.202
Anything else?
Changing the method signature to the following (from to generic parameter objectTField) could fix the issue as far as I understand:
public void Add<TField>(Expression<Func<TField>> accessor, string message)That would match the the method in FieldIdentifier:
| public static FieldIdentifier Create<TField>(Expression<Func<TField>> accessor) |
Metadata
Metadata
Assignees
Labels
Pillar: Technical DebtPriority:2Work that is important, but not critical for the releaseWork that is important, but not critical for the releasearea-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.This issue describes a behavior which is not expected - a bug.feature-blazor-form-validationThis issue is related to forms validation in BlazorThis issue is related to forms validation in Blazorhelp candidateIndicates that the issues may be a good fit for community to help with. Requires work from eng. teamIndicates that the issues may be a good fit for community to help with. Requires work from eng. team