我在检查密码是否与确认密码匹配时遇到问题。
这是用户输入密码的模式表单
<div class="form-group has-feedback" ng-class="addUser.password.$valid ? 'has-success' : 'has-error';" ng-hide="hideField">
<label class="control-label" for="password">Password</label>
<input type="password" class="form-control" name="password" ng-model="user.password" required ng-minlength="8">
<span class="glyphicon form-control-feedback" ng-class="addUser.password.$valid ? 'glyphicon-ok' : 'glyphicon-remove';"></span>
</div>
<div class="form-group has-feedback" ng-class="addUser.confirmpassword.$valid ? 'has-success' : 'has-error';" ng-hide="hideField">
<label class="control-label" for="confirmpassword">Re-enter Password</label>
<input type="password" class="form-control" name="confirmpassword" ng-model="user.confirmpassword" required ng-minlength="8" >
<span class="glyphicon form-control-feedback" ng-class="addUser.confirmpassword.$valid ? 'glyphicon-ok' : 'glyphicon-remove';"></span>
</div>
这是提交按钮
<button type="submit" class="btn btn-primary btn-block" ng-disabled="!allowSubmit(addUser)" ng-click="add();">Save</button>
我想要的是,在提交表单之前,用户输入的密码必须与确认密码匹配。我正在做这样的事情。但它没有按我的意愿检查密码。感谢您的帮助。
$dialogScope.add = function() {
if ($dialogScope.user.password != $dialogScope.user.confirmpassword)
{
dialogScope.errorMessage = "Password does not match!"
}
答案 0 :(得分:0)
在父表单上使用ng-submit="add()"
,然后从提交按钮中删除ng-click="add();"
。
$dialogScope.add = function() {
if ($dialogScope.user.password != $dialogScope.user.confirmpassword) {
dialogScope.errorMessage = "Password does not match!";
return false;
}
// Do what you want to do after for form submission
};