Let me start by saying I do not want to use any extensions as I really need to understand this fundamentally.
I can handle one:many relationships in my forms just fine if I am populating the selection from a predefined query. Whether checkboxes, radios, or multi-select lists it is pretty straightforward.
What I’m having trouble with is the create action for a tabular input field where the number of inputs is not predetermined. In other words, I’m starting with one field and cloning the inputs.
There are two issues I’m running into:
- My related data comes across as the following:
RelatedModel(Has_Many)
field1
0: data1
1: data2
…
field2
0: data1
1: data2
…
What I want is the following:
RelatedModel(Has_Many)
0
field1: data1
field2: data2
…
- What is the best practice to generate the cloned fields? Clientside javascript or ajax method in controller?
I am starting out using clientside javascript, but on validation error the data is not repopulated! I also can’t figure out how to get the data in the $_POST format I want this way. It seems like there isn’t a way to have the data in the array keyed correctly if I use clientside javascript to clone rows versus using ajax and renderPartial in the controller.
Thanks!