Skip to content

Feature Request: Add Minimum Limit for MultiSelect #322

@nakabor

Description

@nakabor

Description

Currently, the MultiSelect component allows setting a maximum limit for selections using the Limit() method. However, there's no way to set a minimum number of required selections. Adding a minimum limit would enhance form validation capabilities.

Proposed Solution

Introduce a new method, perhaps called MinLimit(n int), to set the minimum number of selections required for a MultiSelect field.

P.S. AtLeast(n int) might be great as well.

Example Usage

huh.NewMultiSelect[string]().
    Title("Select at least 2 but no more than 4 toppings").
    Options(
        huh.NewOption("Cheese", "cheese"),
        huh.NewOption("Tomatoes", "tomatoes"),
        huh.NewOption("Onions", "onions"),
        huh.NewOption("Lettuce", "lettuce"),
        huh.NewOption("Pickles", "pickles"),
    ).
    MinLimit(2).  // New method to set minimum selections
    Limit(4).     // Existing method for maximum selections
    Value(&toppings)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions