Tôi đang viết chỉ thị xác minh mật khẩu:
Directives.directive("passwordVerify",function(){
return {
require:"ngModel",
link: function(scope,element,attrs,ctrl){
ctrl.$parsers.unshift(function(viewValue){
var origin = scope.$eval(attrs["passwordVerify"]);
if(origin!==viewValue){
ctrl.$setValidity("passwordVerify",false);
return undefined;
}else{
ctrl.$setValidity("passwordVerify",true);
return viewValue;
}
});
}
};
});
html:
<input data-ng-model='user.password' type="password" name='password' placeholder='password' required>
<input data-ng-model='user.password_verify' type="password" name='confirm_password' placeholder='confirm password' required data-password-verify="user.password">
Cho 2 trường mật khẩu trong một biểu mẫu, nếu cả hai giá trị mật khẩu bằng nhau thì trường bị ảnh hưởng bởi lệnh là hợp lệ. Vấn đề là nó hoạt động theo một chiều (tức là khi tôi nhập mật khẩu vào trường xác minh mật khẩu). Tuy nhiên, khi trường mật khẩu ban đầu được cập nhật, xác minh mật khẩu không hợp lệ.
Bất kỳ ý tưởng nào về cách tôi có thể có "xác minh ràng buộc hai chiều?"