form edit for a model with hasMany association.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

form edit for a model with hasMany association.

Mauro
Supplier haMany phones.
I want to update phone inside a supplier form, is it correct doing something like this?

<g:each in="${supplierInstance.phones}" var="phone" status="i">
    <div class="${hasErrors(bean: supplierInstance, field: "phone.number", 'has-error')} ">
      <label for="phone.number"><g:message code="phone.number.label" default="Phone[${i}]" /></label>
      <input type="number" class="form-control" name="phones[${i}].number" value="${phone?.number}">               
    </div>
</g:each>


Reply | Threaded
Open this post in threaded view
|

Re: form edit for a model with hasMany association.

Jeff Scott Brown-2


On January 14, 2014 at 9:44:47 AM, Mauro Sanna ([hidden email]) wrote:

>  
> Supplier haMany phones.
> I want to update phone inside a supplier form, is it correct doing  
> something like this?
>  
>  
>
> 'has-error')} ">
> > default="Phone[${i}]" />
> > value="${phone?.number}">
>

>  
>  

At a glance I think that will work if phones is a List.  If phones is a Set I think you will need to include a hidden form field for each number where the name is phones[${i}].id and the value is ${phone.id}.



JSB

Jeff Scott Brown
[hidden email]

Autism Strikes 1 in 166  
Find The Cause ~ Find The Cure
http://www.autismspeaks.org/



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: form edit for a model with hasMany association.

Mauro
On 14 January 2014 17:10, Jeff Scott Brown <[hidden email]> wrote:


On January 14, 2014 at 9:44:47 AM, Mauro Sanna ([hidden email]) wrote:
>
> Supplier haMany phones.
> I want to update phone inside a supplier form, is it correct doing
> something like this?
>
>
>
> 'has-error')} ">
> > default="Phone[${i}]" />
> > value="${phone?.number}">
>

>
>

At a glance I think that will work if phones is a List.  If phones is a Set I think you will need to include a hidden form field for each number where the name is phones[${i}].id and the value is ${phone.id}.



I need to add
List phones in Supplier model?

Reply | Threaded
Open this post in threaded view
|

Re: form edit for a model with hasMany association.

Jeff Scott Brown-2


On January 14, 2014 at 10:21:57 AM, Mauro Sanna ([hidden email]) wrote:
>  
>
> >
> > I need to add
> List phones in Supplier model?
>

Only if you want to store the elements in a List. The default collection type for your hasMany relationships is Set.



JSB


Jeff Scott Brown
[hidden email]

Autism Strikes 1 in 166  
Find The Cause ~ Find The Cure
http://www.autismspeaks.org/



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email