CodeBeam.MudBlazor.Extensions icon indicating copy to clipboard operation
CodeBeam.MudBlazor.Extensions copied to clipboard

MudChipField - Required property should enforce the presence of chips

Open anilmawji opened this issue 2 years ago • 1 comments
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";
        }
    }
}

anilmawji avatar Oct 01 '23 01:10 anilmawji

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.

mckaragoz avatar Oct 01 '23 16:10 mckaragoz