Max Selectable Options in Checkbox List
Hello,
Is there any way I can limit the Checkbox list with Max selectable options?
I have around 50+ options to select from and I want users to only select any 5 options. After 5 options it should not let the user check any checkbox.
currently, I am just preventing this by using rules.
Could anyone please suggest anything? 🙂
Thank you.
Solution:Jump to solution
Does combining your Rule with a closure on
disableWhen
work? The closure could count how many are selected and return true when it's too many.
https://filamentphp.com/docs/3.x/forms/fields/checkbox-list#disabling-specific-options...5 Replies
Using max:5 maybe
thank you for your reply
I can validate it but after the button click
what I want is when the user selects 5 options, all other options should get disabled.
The validation rule is an okay way to handle it. It might even be the only way. (EDIT: er, well, not for disabling the rest ... hmmm)
You could make the form more performant if there are lots of other fields on the page by telling it to only validate that component, instead of the whole form when the debounce is triggered:
With checkboxes the use of
reactive()
may be fine, since it requires individual clicks, which are slower than typing in a text field. But I found that changing from reactive
to debounce(400)
improved page performance on a large form ... when on a textarea field. ... so, again, may not make any diff on CheckboxList.Solution
Does combining your Rule with a closure on
disableWhen
work? The closure could count how many are selected and return true when it's too many.
https://filamentphp.com/docs/3.x/forms/fields/checkbox-list#disabling-specific-optionsThanks a lot, mate.
this works like a charm.
For those who are looking for a similar kinda solution: