Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Add Minimum Limit for MultiSelect #322

Open
nakabor opened this issue Jul 24, 2024 · 0 comments · May be fixed by #336
Open

Feature Request: Add Minimum Limit for MultiSelect #322

nakabor opened this issue Jul 24, 2024 · 0 comments · May be fixed by #336

Comments

@nakabor
Copy link

nakabor commented Jul 24, 2024

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)
@yutasb yutasb linked a pull request Jul 27, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant