First time working wtih checkboxes in Grails. What I want the checkbox to do is simply set a boolean variable to true if checked.
From the form.gsp:
<div class="form-group col-md-12 ${hasErrors(bean: apiInstance, field: 'oneWay', 'error')} ">
<label for="oneWay">
<g:message code="api.oneway.label" default="One Way" />
</label>
<g:checkBox name="oneWay " value="true" checked="${apiInstance?.oneWay == 'true'}"/>
</div>
In my domain class I have this defined:
Boolean oneWay = false
And in the service that is called from the controller I check the status of oneWay:
if (apiInstance.oneWay == true) {
log.info("One way flag is set.")
} else {
log.info("One way flag is not set.")
}
It's always false even when I check the checkbox. What act of stupidity am I committing? :D
I don't think you need to use the value and checked attributes, just use value like:
<g:checkBox name="oneWay " value="${apiInstance?.oneWay}" />