Created
July 18, 2015 05:23
-
-
Save Lazhari/0695d21b5ef7fee8503d to your computer and use it in GitHub Desktop.
Directive Angularjs : Confirm password
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('app') | |
.directive('validateEquals', function () { | |
return { | |
require: 'ngModel', | |
link: function(scope, element, attrs, ngModelCtrl) { | |
function validateEqual(value) { | |
var valid = (value === scope.$eval(attrs.validateEquals)); | |
ngModelCtrl.$setValidity('equal', valid); | |
return valid ? value: 'undefined'; | |
} | |
ngModelCtrl.$parsers.push(validateEqual); | |
ngModelCtrl.$formatters.push(validateEqual); | |
scope.$watch(attrs.validateEquals, function() { | |
ngModelCtrl.$setViewValue(ngModelCtrl.$viewValue); | |
}) | |
} | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form ng-submit="submit()" name="register" novalidate> | |
<h2 class="text-center">Register</h2> | |
<div class="form-group"> | |
<label for="exampleInputEmail1">Email address</label> | |
<input name="email" ng-model="email" type="email" class="form-control" id="exampleInputEmail1" placeholder="Email" required> | |
<p class="help-block" ng-show="register.email.$dirty && register.email.$invalid">Please enter a proper email.</p> | |
</div> | |
<div class="form-group"> | |
<label for="passwordInput">Password</label> | |
<input name="password" ng-model="password" type="password" class="form-control" id="passwordInput" placeholder="Password" required> | |
</div> | |
<div class="form-group"> | |
<label for="confirmPasswordInput">Confirm Password</label> | |
<input name="password_confirm" ng-model="password_confirm" type="password" class="form-control" id="confirmPasswordInput" placeholder="Confirm Password" validate-equals="password"> | |
</div> | |
<p class="help-block" ng-show="register.password_confirm.$dirty && register.password_confirm.$invalid ">Please match the Passwords</p> | |
<div class="text-center"> | |
<button type="submit" class="btn btn-primary btn-lg" ng-disabled="register.$invalid">Submit</button> | |
</div> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment