Dynamically Added "sub-Forms" In An Outer Form - Multiple Submission Of The Inner Ones And Then The Outer One

Hi,

I would like to have a form from model A and in the form an ajax call that will be producing (partial) forms from a different model B. I would like to be able to submit these dynamically produced inner forms when I submit the outer one - any ideas how this can be done?

I will have something like that


<form outer>  

Create Car:




Car Types: 

<input:AutoComplete from already available car types> or add new (nested form) with ajax

<form inner/>Create new Car Type:   type:<input/><form inner/>

...

...

<form inner/>Create new Car Type:   type:<input/><form inner/>  




</form>

The inner forms are creating new objects that their ids will be used to do insertions in join table car_type

when I submit the outer I want the inner forms (that I know what model they are going to be validated against) to be submitted and then to return some ids that I will use in the join table insertions, then validate the outer form and submit it as well - the number of inner forms are not known in advance as they are produced dynamically through ajax…

Thank you in advance :)