开发者

Grails checkbox simple question

开发者 https://www.devze.com 2023-03-08 06:14 出处:网络
I have this checkBox in my view inside a fo开发者_高级运维rm: <g:checkBox name=\"myCheckbox\" value=\"${false}\" />

I have this checkBox in my view inside a fo开发者_高级运维rm:

<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"
}
0

精彩评论

暂无评论...
验证码 换一张
取 消