You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
EditForm only validates the object in its Model parameter. If the object is a complex object (such as a Person with an Address) its complex properties are not also validated.
To Reproduce
Steps to reproduce the behavior:
Using this version of ASP.NET Core '3.0.0-preview8.19405.7
Create a new Blazor app
Replace the contents of index.razor with the following mark-up
@page "/"
@using System.ComponentModel.DataAnnotations
@if (LastSubmissionStatus != null)
{
<h1>Last submission at @LastSubmissionTime.ToString("hh:mm:ss") was @LastSubmissionStatus</h1>
}
<EditForm Model=Person1 OnValidSubmit=ValidFormSubmitted OnInvalidSubmit=InvalidFormSubmitted>
<DataAnnotationsValidator/>
<ValidationSummary/>
Person name <InputText @bind-Value=Person1.Name/><br/>
Country <InputText @bind-Value=Person1.HomeAddress.Country/><br/>
<input type="submit" value="Validate"/>
</EditForm>
@code {
Person Person1;
string LastSubmissionStatus;
DateTime LastSubmissionTime;
protected override void OnInitialized()
{
base.OnInitialized();
Person1 = new Person
{
Name = null,
HomeAddress = new Address
{
Country = null
}
};
}
void ValidFormSubmitted(EditContext context)
{
LastSubmissionTime = DateTime.Now;
LastSubmissionStatus = "valid";
}
void InvalidFormSubmitted(EditContext context)
{
LastSubmissionTime = DateTime.Now;
LastSubmissionStatus = "invalid";
}
class Person
{
[Required]
public string Name { get; set; }
public Address HomeAddress { get; set; }
}
class Address
{
[Required]
public string Country { get; set; }
}
}
5: Run the app
6: Enter a value for Name
7: Click the Validate button
Expected: An invalid form, with Country highlighted
Actual: OnValidSubmit is executed
8: Enter a value for Country
9: Click Validate
10: Delete the value for Country
11: Click Validate
Expected: OnInvalidSubmit should be executed
Actual: It is not, nor is OnValidSubmit
The text was updated successfully, but these errors were encountered:
Describe the bug
EditForm only validates the object in its
Model
parameter. If the object is a complex object (such as a Person with an Address) its complex properties are not also validated.To Reproduce
Steps to reproduce the behavior:
5: Run the app
6: Enter a value for Name
7: Click the Validate button
Expected: An invalid form, with
Country
highlightedActual:
OnValidSubmit
is executed8: Enter a value for Country
9: Click Validate
10: Delete the value for Country
11: Click Validate
Expected:
OnInvalidSubmit
should be executedActual: It is not, nor is
OnValidSubmit
The text was updated successfully, but these errors were encountered: