Checkboxlist and limits
I know there is an option for Selects, but is not not a solution for limiting the number of items selected in a checkboxlist? I know I can do a rule, but wanting something with a bit better UX than that. Figured I would ask here while I dig.
10 Replies
I don't think theres anything UI-wise... yet
I just found https://stackoverflow.com/questions/61903452/stop-checkbox-from-being-check-in-alpinejs. Will give it a go next time I’m at my computer
Stack Overflow
Stop checkbox from being check in alpineJS?
i started using alpine JS in my project and encountered this situation, i dont really know the best way to approach this. I have a input checkboxes and i need to restrict the user to only select 12...
Would obviously need to be combined with some sort of messaging
it just needs x-bind:disabled i think
@mark_chaney did that resolve it for you?
@toeknee_iom I came up with https://codepen.io/MACscr/pen/MWqoNvN?editors=1001, but when i tried to use it within the form, I didnt have any luck. Wasnt sure important and I think a rule is good enough for now.
its a starting point at least for someone else
The basic count idea i had at first didnt work consistently as
:disabled
wasnt updating on every change, so why i had to setup a method insteadOk that makes sense, not elegant but it works 🙂
It would make sense a limit could be set with ->limit() with a notice as to why they can't select. Disabling wouldn't always work as you won't be able to de-toggle.
@toeknee_iom you can detoggle, did you try out the codepen?
With yours you can :-), sorry I was thinking out loud!