I'm generating nested form from a json object say formObject and binding the values in the json object itself. I'm parsing the values recursively and pulling out the actual data say dataObject at submit.
I can retrieve the dataObject in a linear form like this one. http://jsfiddle.net/DrQ77/80/.
<select ng-model="Answers[question.Name]" ng-options="option for option in question.Options">
In contrast to the above, http://jsfiddle.net/DrQ77/92/ has some recursion. I've renamed question to element for it to represent both questions & sections. Every section can have multiple questions & again, multiple sections (this is what I meant by nesting). What I want eventually is an object in a form below with any level of nesting.
Answers=[{
section:"Personal",
values:[{GenderQuestion:"Male"},{MaritalStatus:"Married"},{section:"Sub Personal",values:[{LivingWith:"Alone"}]}]
}, {
section:"Random",
values:[{ColorQuestion:"Red"}],
},
{SectionLess:"opt1"}]
This is one solution & I can get it on submit, $scope.Answers from the first fiddle does not (I think) allow that kind of nesting. But when I have to update an existing dataObject, I felt a need to map the dataObjects onto the formObject before rendering it, and then parsing again on submit. Now this isn't MVC, doesn't look elegant (due to the recursion) & I think there's an 'angular way' for this.
Has anybody tried this & got it working in a better fashion? How do I get around it?
$scope.Answersis constantly up-to-date and ready to be submitted at any time, due to Angular's data-binding. But maybe it's because I'm too sleepy :) Anyways, It'd be cool if you could make the fiddle more elaborated (but not too much - hello-worldish style appreciated) to fully illustrate downsides of your current approach.