Reputation: 884
So I've got a basic, g:each like so: -
<g:each in="${results}" status = "i" var="item">
<tr id = ${i} class="${(i % 2) == 0 ? 'even' : 'odd'}" name="main">
<td colspan="3">
<table id = "sub">
<tr>
<td><b>Action</b></td><td>
<g:select style="width:375px;"name="events[$i].id" from="${framework.EventType.list(sort:"userEventType")}" required="required" optionKey="id" value="${item.event_id}" /></td>
<td><b>Object</b></td>
<td>
<input type="text" name="any[$i].id">
<g:select style="width:550px;"id="objectID[$i]" name="objectID[$i].id" from="${framework.Object.list(sort:"objDesc")}" optionKey="id" required="" value="${item.object_id}" class="many-to-one"/>
<richui:autoComplete name="autocomp[$i].id" value= "${item.object_description}" action="${createLinkTo('dir': 'object/searchAJAX')}" maxResultsDisplayed="20" minQueryLength ="3" onItemSelect="youPickedThis(id,'autocomp[$i].id')" />
</td>
</tr>
</table>
</td>
</tr>
</g:each>
Absolutely everything within here is generated in the html with the correct names (i.e. [$i] becomes [0] on the first each, [1] on the second and so on. But the very first input (type text) just names them all "any[$i].id"!
Anyone have the remotest idea why the first input is too good to pick up up whereas the other elements just get on with it as they should?
Upvotes: 1
Views: 183
Reputation: 122364
The only difference I can see is that the <input type="text">
is a plain HTML tag whereas all the other places where you're using $i
are attributes of GSP tags (richui:autocomplete
and g:select
). Try using ${i}
instead:
<input type="text" name="any[${i}].id">
I wasn't aware that the short form (without using braces) was valid anywhere in a GSP, but the longer brace form will definitely work in all cases.
Upvotes: 1