I have a basic structure as such:
<g:form>
actionSubmit
</g:form>
<g:form>
actionSubmit
</g:form>
<g:each in personList - variable=person>
<tr>
<td><g:checkBox name="personList" value="${person.id}" checked="${false}"/></td>
<td>
<g:form>
actionSubmit
</g:form>
</td>
</tr>
</g:each>
Each of these forms relies on the personList checkbox array as a variable. The prior edition of my code wrapped the entire div in a form, which worked but caused problems when I added the third form in the table.
How can I pass the selected checkboxes? I have checkbox that selects all of the boxes – I just need to assign a variable/hiddenField with that array of selected boxes.
Thanks!
Edit
The issue with having a single form is that I have a column in each row has the ability to add elements to a one to many relationship. If I could pass the person.id with the corresponding action submit (so if I hit the actionSubmit on row 2, I want to pass person.id of row 2), then this is a piece of cake.
However, whenever I tried to tie the person ID, I end up with an array of ALL person IDs. So I figured the only way around this is to have separate forms.
<td>
<div id="reportsToResultsDiv2_${person.id}" class="reportsToResultsDiv2_${person.id}">
<g:select id="reportsTo" name="reportsTo.id" from="${rtResults}" optionKey="id" value="" />
<g:actionSubmit action="addReportsTo" value="Add" params="[c_id:'${person.id}']"/>
</div>
</td>
I don’t think checkbox supports both value and checked in that way.
Perhaps this is what you want?