Answer the question
In order to leave comments, you need to log in
Field validation for identity in Angular?
Tell me how to validate the password field for comparison with the first one, that is, I check the first password field with the second one and if they are equal, then I unlock the button
JS
.directive('pwCheck', function () {
return {
require: 'ngModel',
link: function (scope, elem, attrs, ctrl) {
var me = attrs.ngModel;
var matchTo = attrs.pwCheck;
scope.$watch('[me, matchTo]', function(value){
ctrl.$setValidity('pwmatch', scope[me] === scope[matchTo] );
});
}
}
})
<form novalidate name="regForm" ng-submit="submit()">
<div class="row">
<label for="name">Имя: </label><input name="name" ng-model="dataRegForm.name" type="text" ng-required="">
</div>
<div class="row">
<label for="name">Email: </label><input name="email" ng-model="dataRegForm.email" type="email" ng-required="">
</div>
<div class="row">
<label for="pass">Ваш пароль: </label><input name="pass" ng-model="dataRegForm.password" type="password" ng-required="">
</div>
<div class="row">
<label for="pass">Повторите пароль: </label><input name="pass2" ng-model="dataRegForm.password_two" type="password" pw-check="dataRegForm.password" ng-required="">
</div>
<div class="msg-block" ng-show="true"> <span class="msg-error" ng-show="regForm.dataRegForm.password_two.$error.pwmatch">Passwords don't match.</span>
</div>
<div class="row">
<input ng-disabled="regForm.$invalid" type="submit" value="Войти">
</div>
</form>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question