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
Labels
enhancement New feature or request multiselect

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
@caarlos0 caarlos0 added enhancement New feature or request multiselect labels Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request multiselect
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants