Checkbox validation #610
-
I have an issue: I have DTOs that I use for both my API and Frontend. Right now I want to implement a form with a checkbox and have Laravel Data handle the validation for me. But this just doesn't work. It always tells me that I have to provide either true or false as the value. But checkboxes return null or "on" in HTML. Even with a cast it just doesn't work. In my opinion that is a simple thing the package should be able to handle. How did you people solve this issue? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
We're just using the laravel validator here, it does not accept 'on' as a value. You could create your own validation rule in this case. |
Beta Was this translation helpful? Give feedback.
-
Bit late to the party but had the same problem. You can use the default Laravel validator by adding value="1" to the checkbox markup. The Laravel validator does accept "1" as a value: https://laravel.com/docs/11.x/validation#rule-boolean |
Beta Was this translation helpful? Give feedback.
We're just using the laravel validator here, it does not accept 'on' as a value. You could create your own validation rule in this case.