下面的代码说明了编辑员工表单和新员工表单的角度js验证。编辑表单验证工作正常,新表单没有。请帮忙。
我检查了所有标签,确保设置为必需。 newUser字段设置正确,如果填写了所有字段,它将创建用户。
<div class="panel panel-primary">
<div class="panel-heading">
New Employee
</div>
<div class="panel-body">
<form role="form" novalidate angular-validator name="addUserForm" angular-validator-submit="Register()">
<table class="headerLayout">
<tr>
<td style="padding-right: 3px;">First Name:</td>
<td style="padding-bottom: 3px;">
<input type="text" name="inputFirstName" class="form-control" ng-model="newUser.FirstName"
placeholder="FirstName" validate-on="blur" required required-message="'First Name is required'">
</td>
</tr>
</table>
</form>
</div>
<div class="panel-footer clearfix">
<div class="pull-right">
<button type="button" class="btn btn-danger" ng-click="cancelCreate()">Cancel</button>
<button type="button" class="btn btn-primary" ng-click="createUser()">Save</button>
</div>
</div>
(function (app) {
'use strict';
app.controller('userNewCtrl', userNewCtrl);
userNewCtrl.$inject = ['$scope', '$modalInstance', 'apiService', 'notificationService'];
function userNewCtrl($scope, $modalInstance, apiService, notificationService) {
$scope.cancelCreate = cancelCreate;
$scope.createUser = createUser;
function createUser() {
$scope.newUser.Roles = $scope.selectedRoles;
apiService.post('/api/users/add/', $scope.newUser,
createUserCompleted,
createUserFailed);
}
function createUserCompleted(response) {
notificationService.displaySuccess($scope.newUser.UserName + ' has been created');
$modalInstance.dismiss();
}
function createUserFailed(response) {
notificationService.displayError(response.data);
}
function cancelCreate() {
$modalInstance.dismiss();
}
}
})(angular.module( 'MYSITE'));
答案 0 :(得分:0)
我只需在表单元素中移动提交按钮即可。