0
最初にAngular Auto Validateを使用していますが、期待どおりに動作していますが、パスワードを比較するカスタム検証を追加します。角度自動検証を使用してカスタム検証を追加
ここでは実際に私のコードです:
<form role="form" name="changePasswordForm" novalidate="novalidate" ng-submit="changePassword()">
<div class="box-body">
<div class="form-group">
<label for="oldPassword">Old Password</label>
<input type="password" class="form-control" id="txtOldPassword" name="oldPassword" ng-model="data.oldPassword" placeholder="Old password" required="required" ng-pattern="/^[A-Za-z]+$/" ng-minlength="6" ng-maxlength="10" ng-pattern-err-type="badOldPassword">
</div>
<div class="form-group">
<label for="newPassword">New Password</label>
<input type="password" class="form-control" id="txtNewPassword" name="newPassword" ng-model="data.newPassword" placeholder="New password" required="required" ng-pattern="/^[A-Za-z]+$/" ng-minlength="6" ng-maxlength="10" ng-pattern-err-type="badNewPassword">
</div>
<div class="form-group">
<label for="confirmNewPassword">Confirm New Password</label>
<input type="password" class="form-control" id="txtConfirmNewPassword" name="confirmNewPassword" ng-model="data.confirmNewPassword" placeholder="Confirm new password" required="required" ng-pattern="/^[A-Za-z]+$/" ng-minlength="6" ng-maxlength="10" ng-pattern-err-type="badConfirmNewPassword">
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
var userApp = angular
.module("userModule", ['jcs-autoValidate'])
.run(function(defaultErrorMessageResolver) {
defaultErrorMessageResolver.getErrorMessages().then(function(errorMessages) {
errorMessages['badOldPassword'] = 'Old password must contain only alphabets.';
errorMessages['badNewPassword'] = 'New password must contain only alphabets..';
errorMessages['badConfirmNewPassword'] = 'Confirm password must contain only alphabets.';
})
})
.controller('userController', function($scope, $http, $log) {
$scope.data = {};
$scope.changePassword = function() {
alert('form submitted');
}
});
どうもありがとうその加工さ –