I want to disable submit button when validate confirm password. I followed this model:
Angularjs:
var app = angular.module('myapp', ['UserValidation']);
angular.module('UserValidation', []).directive('validPasswordC', function () {
return {
require: 'ngModel',
link: function (scope, elm, attrs, ctrl) {
ctrl.$parsers.unshift(function (viewValue, $scope) {
var noMatch = viewValue != scope.myForm.password.$viewValue
ctrl.$setValidity('noMatch', !noMatch)
})
}
}
})
view :
<div ng-app="myapp">
<form name="myForm">
<label for="password">Password</label>
<input type="password" id="password" name="password" ng-model="formData.password" ng-minlength="8" ng-maxlength="20" ng-pattern="/(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z])/" required />
<span ng-show="myForm.password.$error.required && myForm.password.$dirty">required</span>
<span ng-show="!myForm.password.$error.required && (myForm.password.$error.minlength || myForm.password.$error.maxlength) && myForm.password.$dirty">Passwords must be between 8 and 20 characters.</span>
<span ng-show="!myForm.password.$error.required && !myForm.password.$error.minlength && !myForm.password.$error.maxlength && myForm.password.$error.pattern && myForm.password.$dirty">Must contain one lower & uppercase letter, and one non-alpha character (a number or a symbol.)</span>
<br />
<label for="password_c">Confirm Password</label>
<input type="password" id="password_c" name="password_c" ng-model="formData.password_c" valid-password-c required />
<span ng-show="myForm.password_c.$error.required && myForm.password_c.$dirty">Please confirm your password.</span>
<span ng-show="!myForm.password_c.$error.required && myForm.password_c.$error.noMatch && myForm.password.$dirty">Passwords do not match.</span>
<br />
<button type="submit" class="btn" ng-disabled="!myForm.$valid">Submit</button>
</form>
</div>
But the problem is that It does not check for password field, When the submit button enable, I input again password field another values which is different Confirm password and the submit button is still enable.
thankyou verymuch