BlazorStrap
BlazorStrap copied to clipboard
Validation on BSForm object with DataAnnotation being ignored
I have for example the class:
public class Person
{
[Required]
public string Name {get;set;}
private MoreInfo moreInfo;
public MoreInfo MoreInfo
{
get
{
if (moreInfo == null)
{
moreInfo = new MoreInfo();
}
return moreInfo;
}
set
{
filiacionModel = value;
}
}
}
public class MoreInfo
{
[Required]
public string Country {get;set;}
}
@code{
Person Model = new Person();
}
<BSForm @ref="formAdd" Model="@Model" OnValidSubmit="@Add">
<BSFormGroup Class="mb-3">
<label>Name </label>
<BSInput InputType="InputType.Text" @bind-Value="@Model.Name"></BSInput>
<BSFormFeedback For="@(() => Model.Name)"></BSFormFeedback>
</BSFormGroup>
<BSFormGroup Class="mb-3">
<label>Country</label>
<BSInput InputType="InputType.Text" @bind-Value="@Model.MoreInfo.Country"></BSInput>
<BSFormFeedback For="@(() => Model.MoreInfo.Country)"></BSFormFeedback>
</BSFormGroup>
</BSForm>
What is happening is that the validation on the subclass is not firing, is this normal? Only the Name, in this case, jumps as required, if I write a value in Name validation pass. But the intention is that Country has to be required.
Thanks in advance
You need <DataAnnotationsValidator />
inside BSForm if your using Data Annotations to validate