Hi,
I have one child component and one parent component. The child component contains two RadzenDropDown
one is for category and one is for product. I want to validate the product.
Child component:-
<RadzenDropDown class="form-control" placeholder="Select Category"
AllowClear="true"
AllowFiltering="true"
Multiple="true"
FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
TextProperty="Name"
ValueProperty="Id"
@bind-Value=@idCategory
Data = @_listCategory
Change=@(args => onProductsChange(args)) />
<RadzenDropDown class="form-control" placeholder="Select Product"
AllowClear="true"
AllowFiltering="true"
Multiple="true"
FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
TextProperty="Name"
ValueProperty="Id"
@bind-Value=@idProducts
Data = @_listProducts />
<ValidationMessage For="@(() => validProduct)"
style="color:red; font-weight:bold;" />
@code{
[Parameter]
public string validProduct = "";
}
Parent component:-
<ProductSearch @ref="productSelection" validProduct=@validProduct ></ProductSearch>
@code {
public string validProduct = "";
private async void OnValidSubmit()
{
if(model.idProduct == null){
//what should I do here? Actually I want show error message like "Product is Required"
}
}
}
Parent component model class:-
[Required(ErrorMessage = "Product is Required")]
public string? idProduct { get; set; }
How can I do this ?