I have a form that is being populated with information from a table. When I the record has a role or multiple roles it displays as expected however I cannot add additional roles, and I cannot add any roles to the record if there was none. Something is wrong with my $add() function.
Another issue is the password and confirm password are displaying the same data. I am trying to figure this out right now as well.
<form ng-model="current">
<fieldset>
<legend>
<a href="" alt="Register" class="btn btn-mini btn-success" ng-click="newItem()"><i
class="icon-plus-sign icon-white"></i> New </a>
Detail
</legend>
<label>First Name</label>
<input type="text" placeholder="First Name" ng-model="current.firstName" value="current.firstName"
ng-disabled="isKey('lastName')">
<label>Last Name</label>
<input type="text" placeholder="First Name" ng-model="current.lastName" value="current.lastName"
ng-disabled="isKey('firstName')">
<label>Email</label>
<input type="text" placeholder="user@example.com" ng-model="current.email" value="current.email"
ng-disabled="isKey('email')">
<label>Password</label>
<input type="password" placeholder="Password" ng-model="current.password" value="current.Pass"
ng-disabled="isKey('Pass')">
<label>Confirm Password</label>
<input type="password" placeholder="Confirm Password" ng-model="current.password" value="current.Pass"
ng-disabled="isKey('Pass')">
<label>Enabled</label>
<select ng-model="current.enabled" ng-disabled="isKey('enabled')">
<option value=true>Enabled</option>
<option value=false>Disabled</option>
</select>
<div class="role" ng-repeat="role in current.roles">
<label>User Roles</label>
<select ng-model="role.roleName" ng-disabled="isKey('role')">
<option value="ROLE_USER">User</option>
<option value="ROLE_ADMIN">Administrator</option>
</select>
</div>
<label></label>
<a class="btn btn-primary" ng:click="current.role.$add()">Add Role</a>
<label></label>
<a href="#askCreateUser" alt="Register" role="button" class="btn btn-success" data-toggle="modal"
ng-click="setDataOperation('Update')"><i class="icon-edit icon-white"></i> Update </a>
<a href="#askCreateUser" alt="Register" role="button" class="btn btn-warning" data-toggle="modal"
ng-click="setDataOperation('Delete')"><i class="icon-trash icon-white"></i> Delete </a>
</fieldset>
</form>
I found that this was due to trying to push to an empty array. After adding the below function I was able to add elements without issue.
$scope.addRole = function () {
if ($scope.current.roles != undefined) {
$scope.current.roles.push({});
}
else {
$scope.current.roles = new Array();
$scope.current.roles.push({});
}
};