I have a checkbox on my GSP page as follows (which was stolen directly from the scaffolded "create" code for my domain object)...
<tr class="prop">
<td valign="top" class="name">
<label for="isSelling"><g:message code="person.isSelling.label" default="Is Selling" /></label>
</td>
<td valign="top" class="value ${hasErrors(bean: personInstance, field: 'isSelling', 'errors')}">
<g:checkBox name="isSelling" value="${personInstance?.isSelling}" />
</td>
</tr>
This works just fine, except when I look at the elements in the resulting form I have a hidden checkbox alongside the real one...
<tr class="prop">
<td valign="top" class="name">
<label for="isSelling">Is Selling</label>
</td>
<td valign="top" class="value ">
<input type="hidden" name="_isSelling" />
<input type="checkbox" name="isSelling" id="isSelling" />
</td>
</tr>
My questions are:
- why is it there?
- what does Grails do with it?
- if I am looking at the form values in Javascript, which input value sh开发者_运维问答ould I take?
Just inspecting what happens when the checkbox gets set on and off in my page, it appears that the hidden one is ignored, so I am imagining there is some cunning processing going on when the submit action occurs which looks at the _isSelling and isSelling for some magical purpose. Anyone have any insight into what Grails is doing?
Thanks
That's a spring thing. It adds that checkbox so that unchecked boxes are accountable. Some browsers won't push any information about an unchecked box so the hidden box is added to prevent binding errors.
精彩评论