Reputation: 15275
I'm working on a Blazor application using MudBlazor and need to localize validation messages (like "Required") globally across all components. Currently, I have to set the validation message for each input individually, which isn't maintainable. For example, I currently have to do this for each component:
<MudSelect T="int?" @bind-Value="_input.SaleTypeId"
RequiredError="@Localizer["Required"]"
Label="@Localizer["SelectSaleType"]"
Dense="true"
Required="true">
@foreach (var saleType in SaleTypes)
{
var id = (int?)saleType.Id;
<MudSelectItem Value="@id">@saleType.Title</MudSelectItem>
}
</MudSelect>
Upvotes: 1
Views: 48
Reputation: 9247
According to this:
https://mudblazor.com/features/localization#translation-keys
MudBlazor does not currently support the MudSelect_Required key.
I guess you could create a custom MudSelect. Something like:
public class MyCustomMudSelect<T> : MudSelect<T>
{
protected override void OnParametersSet()
{
if (Required)
RequiredError = _localizer["Required"];
}
}
Then use this custom MudSelect instead. It should automatically set the value on the base MudSelect.
Upvotes: 3