rob-balfre / svelte-select

Svelte Select. A select component for Svelte
https://svelte-select-examples.vercel.app
Other
1.26k stars 175 forks source link

Multiselect: Limit to number of selected items #490

Closed EskelCz closed 1 year ago

EskelCz commented 1 year ago

Is there a way to limit the number of selected items? Thanks.

rob-balfre commented 1 year ago

Not internally but there are a few ways to achieve the same result with reactive statements. How do you want it to work? Lock more selections when limit is reached?

On Tue, 1 Nov 2022, 11:50 am David Spohr, @.***> wrote:

Is there a way to set the maximum number of selected items? Thanks.

— Reply to this email directly, view it on GitHub https://github.com/rob-balfre/svelte-select/issues/490, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAUAM7VZZIAJLSRQSRO7BZDWGBSMHANCNFSM6AAAAAARTTFDXY . You are receiving this because you are subscribed to this thread.Message ID: @.***>

EskelCz commented 1 year ago

@rob-balfre Exactly, disabling the ability to select more than the limit, until some are deselected again. Maybe also triggering an event, so that I can hook up some explanation (alert, label, shaking animation, etc.) to the user.

In my case it's just a prevention of abuse, if someone tries to select hundreds of items just to see what happens. Don't want to even test that scenario. :)

rob-balfre commented 1 year ago

V5?

EskelCz commented 1 year ago

Yep

rob-balfre commented 1 year ago

@EskelCz here's one way of doing it... prob a few other ways too.

https://svelte-select-examples.vercel.app/examples/advanced/limit-multi-value

EskelCz commented 1 year ago

I'd prefer an integrated feature, for the sake of clean code, but this does the trick for now. Thanks a lot