I have this checkBox in my view inside a form:
<g:checkBox name="myCheckbox" value="${false}" />
In my controller, I how do I know if it is checked or not?
I tried:
if(!params.myCheckbox)
// obviously not, because it will always be true
if(params.myCheckBox.checked)
// also dont work.
if (params.myCheckbox) {
println "checkbox is checked"
} else {
println "checkbox is not checked or myCheckbox parameter is missing"
}
If you need to separately handle "checkbox is not checked" and "myCheckbox parameter is missing", use:
if (params.myCheckBox == null) {
println "myCheckbox parameter is missing"
} else if (params.myCheckbox) {
println "checkbox is checked"
} else {
println "checkbox is not checked"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With