0

I have a HTML table that has a form field that can be updated for each row. In each row, I have created a form and when you change the editable field, a button will appear and you can save the change. This happens remotely using the GRAILS g:submitToRemote tag.

I have some hidden fields that also need to be passed.

When I do the following, none of the fields (the 3 hidden ones, nor the single visible ones) are passed the controller:

<g:form action="updatebaseprice" id="${obj.id}" name="form_${obj.id}">
<tr>
    <td>${prod.product.name}</td>
    <td class="text-center">${prod.product.type}</td>
    <td class="text-center"><g:formatNumber number="${prod.product.unitCost}" type="currency" currencyCode="USD" /></td>

    <td class="text-center">
        <div class="row collapse">
    <div class="small-3 columns">
      <span class="prefix radius">$</span>
    </div>
    <div class="small-9 columns">
      <g:field type="text" class="bemt_small_input_field" value="${prod.basePrice}" id="basePrice_${prod.id}" name="basePrice" onchange="Project.updateBasePrice(${prod.id});" maxlength="6"/>
    </div>
  </div>                                                            
    </td>
    <td class="text-center"><span id="display_recoveryPercent_${prod.id}"><g:formatNumber number="${prod.recoveryPercent}" type="number" minFractionDigits="2" maxFractionDigits="2"/></span>%</td>
    <td class="text-center">
        <g:hiddenField name="projectProduct" value="${prod.id}"></g:hiddenField>
        <g:hiddenField name="unitCost" id="unitCost_${prod.id}" value="${prod.product.unitCost}"></g:hiddenField>
        <g:hiddenField name="recoveryPercent" id="recoveryPercent_${prod.id}" value="${prod.recoveryPercent}"></g:hiddenField>
    <g:submitToRemote id="save_button_${prod.id}" class="hidden button alert save_unitprice radius" id="save_button_${prod.id}" url="[action: 'updatebaseprice']" onSuccess="Project.saveBasePrice();" value="Save"/>                                   
    </td>
</tr></g:form>

Using a println params in the controller, nothing in printed.

When I do the following:

<tr>
<td>${prod.product.name}</td>
<td class="text-center">${prod.product.type}</td>
<td class="text-center"><g:formatNumber number="${prod.product.unitCost}" type="currency" currencyCode="USD" /></td>

<td class="text-center">
    <div class="row collapse">
  <div class="small-3 columns">
    <span class="prefix radius">$</span>
  </div>
  <div class="small-9 columns">
    <g:field type="text" class="bemt_small_input_field" value="${prod.basePrice}" id="basePrice_${prod.id}" name="basePrice" onchange="Project.updateBasePrice(${prod.id});" maxlength="6"/>
  </div>
</div>                                                          
</td>
<td class="text-center"><span id="display_recoveryPercent_${prod.id}"><g:formatNumber number="${prod.recoveryPercent}" type="number" minFractionDigits="2" maxFractionDigits="2"/></span>%</td>
<td class="text-center">
<g:form action="updatebaseprice" id="${obj.id}" name="form_${obj.id}">
    <g:hiddenField name="projectProduct" value="${prod.id}"></g:hiddenField>
    <g:hiddenField name="unitCost" id="unitCost_${prod.id}" value="${prod.product.unitCost}"></g:hiddenField>
    <g:hiddenField name="recoveryPercent" id="recoveryPercent_${prod.id}" value="${prod.recoveryPercent}"></g:hiddenField>
<g:submitToRemote id="save_button_${prod.id}" class="hidden button alert save_unitprice radius" id="save_button_${prod.id}" url="[action: 'updatebaseprice']" onSuccess="Project.saveBasePrice();" value="Save"/>                                   
</g:form>
</td>

I get the three hidden params (as excepted), but not the input that is above the form (I don't expect that, given it is outside the form). The question I have is, why is the first way not returning anything, when I expect it to return the three hidden and one visible field values as params?

Thanks

dreed
  • 5
  • 1

1 Answers1

0

The problem is that you're trying to nest a form inside the html table structure.

As you figured out, you can have a form inside a single table cell but trying to put a table row inside a form won't work.

See this question for some more info: Form inside a table

Community
  • 1
  • 1
MattZ
  • 256
  • 1
  • 6