How to show Blazor child component field validation message in parent form #3849
Unanswered
solid-computing
asked this question in
Q&A
Replies: 1 comment
-
You can pass the component.razor
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to submit a form in a blazor web assembly application and in the form, I am using a custom component that will do autocomplete of a field (for company names). The intention is it reuse this component.
I am using the built-in EditForm validation and I have managed to declare the child component field as required (in the child component Company.razor below) but I am unable to get the validation message working for the field that lives in the child component.
Here is a usage of my component is below. My question is how do I pass something like
For="@(() => _company.Name)"
so that validation message starts to show like it does for LastName field.`
<MudTextField Required Label="Last name" Class="mt-3" @bind-Value="_model.LastName" For="@(() => _model.LastName)"/>
<CompanyLogo CompanyName="@_company.Name" Required="true" @bind-Company="_company"/>
@code {
Company _company = new Company(){};
private EditContext? _editContext;
private ValidationMessageStore _messageStore;
Child component: Company.razor
@($"{element.Name}")
`<MudAutocomplete Required="@required" RequiredError="Select a company name" T="Company" Label="Company name"
@bind-Value="_company"
SearchFunc="@SearchForCompanyName" ToStringFunc="@(element => element == null ? null : $"{element.Name}")" MinCharacters="3" DebounceInterval="200">
@code {
`
This is my first blazor app and would highly appreciate any help. Thanks.
Beta Was this translation helpful? Give feedback.
All reactions