Checkbox List, select at least one
Hi, I have a checkbox list where at least one checkbox needs to be selected. I thought it would be easy using the required but it is allowing me to save the form without one checkbox selected
The checkboxlist is in a custom livewire component
I also tried adding
But I cant get this working either. It never even validates the thing
6 Replies
thats because a non checked is also a valid state
for it to be required
can you add a validation rule
min:1
see if that works?
unfortunatly the min method is not present on checkboxlist. Tried the ->rules(['min:1']) but it skips it as well...
I have the feeling that it skips the entire rules() method.
If i do this:
It skips the check... Which is weird right? It should just dump the string when pressed save
Anybody has some insight into these validation rules? I cant get them working π¦
mm
can you solve it with a multi select instead of a checkbox list ? π
Just validate the array and check for at least one true value. This will get you going: https://stackoverflow.com/questions/45758449/laravel-validate-at-least-one-item-in-a-form-array
Stack Overflow
Laravel validate at least one item in a form array
I have a form with a series of numbers in an array:
<input type="number" name="items[{{ $sku }}]" min="0" />
<input type="number" name="items[{{ $sku }}]" min="0" />
<input type="nu...
Allright thanks, but for this to work I need to be able to execute a rule in the ->rules() method. Somehow I cant even get the function inside rules to work...
Show your code, did you create a separate file or are you using a closure? Did you wrap it in an array? This is what the docs describe: https://filamentphp.com/docs/3.x/forms/validation#custom-rules