My dataset is returning a list of employees. I'm attempting to use the fields from the first index to build my form for adding new employees. I'm struggling with reading the form field data to add a new employee. Fiddle is here: http://jsfiddle.net/nicktest2222/AB5Yw/2/
Any help would be greatly appreciated. Thanks in advance.
HTML
<form ng-submit="addTodo()"> <span ng-repeat="t in todos[0].Collection.InputList"> <label>{{t.DisplayName}}</label> <input type="text" name="{{t.FieldName}}"><br> </span> <br> <input class="btn-primary" type="submit" value="Add"> </form>
JS
function TodoCtrl($scope) { $scope.todos = [{ "Header": "Chris Morgan", "Collection": { "InputList": [{ "FieldName": "dpFname", "DisplayName": "First Name", "Required": "1", "AllowEdit": "1", "TabOrder": "1", "InputType": "TEXTBOX", "Style": "", "Validate": "", "InputMask": "", "Options": [], "Value": "Chris" }, { "FieldName": "dpMname", "DisplayName": "Middle Name", "Required": "0", "AllowEdit": "1", "TabOrder": "2", "InputType": "TEXTBOX", "Style": "", "Validate": "", "InputMask": "", "Options": [], "Value": "" }, { "FieldName": "dpLname", "DisplayName": "Last Name", "Required": "1", "AllowEdit": "1", "TabOrder": "3", "InputType": "TEXTBOX", "Style": "", "Validate": "", "InputMask": "", "Options": [], "Value": "Morgan" }] } }]; $scope.addTodo = function () { $scope.todos.push({ Header: $scope.dpFname + " " + $scope.dpLname, Collection: { "InputList": [{ "FieldName": "dpFname", "DisplayName": "First Name", "Required": "1", "AllowEdit": "1", "TabOrder": "1", "InputType": "TEXTBOX", "Style": "", "Validate": "", "InputMask": "", "Options": [], "Value": $scope.dpFname }, { "FieldName": "dpLname", "DisplayName": "Last Name", "Required": "1", "AllowEdit": "1", "TabOrder": "3", "InputType": "TEXTBOX", "Style": "", "Validate": "", "InputMask": "", "Options": [], "Value": $scope.dpLname }, { "FieldName": "dpMname", "DisplayName": "Middle Name", "Required": "0", "AllowEdit": "1", "TabOrder": "2", "InputType": "TEXTBOX", "Style": "", "Validate": "", "InputMask": "", "Options": [], "Value": $scope.dpMname } ] } }); // Clear form fields $scope.dpFname = ''; $scope.dpLname = ''; $scope.dpMname = ''; };
}