Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #### JS ##########
- angular.module('auth')
- .directive('uniqueEmail', function($http, $q) {
- return {
- restrict: 'A',
- require: 'ngModel',
- link: function(scope, elm, attrs, ctrl) {
- ctrl.$asyncValidators.uniqueEmail = function(modelValue, viewValue) {
- return $http.post('/api/user/validate/email/', {email: modelValue}).then(
- function(response) {
- if (!response.data.isValid) {
- return $q.reject(response.data.error);
- }
- return true;
- },
- function(response) {
- return $q.reject("oops, something going wrong!");
- }
- );
- };
- };
- }
- });
- ##### HTML ##########
- <form novalidate class="css-form" name="usrform">
- Email: <input type="email" ng-model="user.email" name="email" unique-email/><br/>
- <span ng-show="usrform.email.$error.uniqueEmail">addres is already in use</span>
- </form>
- <pre>email = "{{usrform.email}}"</pre>
Advertisement
Add Comment
Please, Sign In to add comment