CodeBeam.MudBlazor.Extensions
CodeBeam.MudBlazor.Extensions copied to clipboard
MudChipField - Required property should enforce the presence of chips
trafficstars
Currently, a MudChipField with the Required property set to true simply enforces the presence of text in the nested MudTextFieldExtended. This is counter-intuitive behaviour, as a required MudChipField should instead enforce the presense of chips.
A workaround involves adding a custom validator, however this obviously does not display errors under the chip field itself as usual.
<MudChipField T="string" Values=@chipValues Validation="@(new Func<string, IEnumerable<string>>(RequireChips))" />
@code {
private IEnumerable<string> RequireChips<T>(T newValue)
{
if (chipValues.Count == 0)
{
yield return "This field is required";
}
}
}
We can add chipfield to this:
protected override bool HasValue(T value)
{
return Values?.Any() ?? false;
}
But it doesn't solve all problems, only removes the required error text, the label still shows error color.