Replies: 1 comment 1 reply
-
Thats how HTML works. Here's a related Stack overflow thread https://stackoverflow.com/questions/1809494/post-unchecked-html-checkboxes |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have this checkbox amongst other similar form items.
According to the Adonis 5 docs, it should be submitting 'on' or 'off' as part of the request object to my controller.
When the checkbox is checked and I do
console.log(request[requestData])
, I seeisRestaurant: 'on'
.However, when the checkbox is left unchecked,
isRestaurant
does not exist on my request.This is causing me issues because I want this to be persisted as either true or false, not NULL within my database.
Does Adonis not handle the post of an unchecked checkbox? Meaning we get the default behaviour where an unchecked checkbox isn't sent on the post? If so, what is the recommended approach in the controller to check whether
isRestaurant
is on the request with a validator?Make it optional on the validator and then do
!!validatedPost.isRestaurant
within myawait Post.create({...})
?Thanks
Beta Was this translation helpful? Give feedback.
All reactions