Skip to content

MudChipField - Required property should enforce the presence of chips #284

Closed

Description

@anilmawji

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";
        }
    }
}

Activity

  1. mckaragoz commented on Oct 1, 2023

    @mckaragoz
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions