I am trying to match two text field password whick looks like this:
pwCheck.js
angular.module('installApp')
.directive('pwCheck', function ($http) {
return {
require: 'ngModel',
link: function (scope, elem, attrs, ctrl) {
var firstPassword = '#' + attrs.pwCheck;
elem.add(firstPassword).on('keyup', function () {
scope.$apply(function () {
ctrl.$setValidity('pwmatch', elem.val() === $(firstPassword).val());
});
});
}
}
});
accounts.html
<label>{{label.password}}</label>
<input type="password" class="form-control" id="pw1" name="pw1" ng-model-options="{updateOn:'blur'}" ng-model="user.password" required ></input>
<label>{{label.retypePassword}}</label>
<input type="password" class="form-control" id="pw2" name="pw2" ng-model-options="{updateOn:'blur'}" ng-model="pw2" ng-required="" pw-check="pw1"></input>
<div class="msg-block" ng-show="signupform.$error"><img src = "./images/error-icon.png" width = "25" height = "25" ng-show="signupform.pw2.$error.pwmatch"></img><span class="msg-error" ng-show="signupform.pw2.$error.pwmatch">Passwords don't match.</span></div>
The above code is working fine as expected but gives a horrible user experience. That happen because when I type in the first textfield the message "Password don't match" will show even the user does not finish typing.
The problem is that the validation happens too quickly, before the user has finished typing.
I have tried to solve this by adding ng-model-options="{updateOn:'blur'}" but the problem is still exist.
Help! Thanks in advance