Guest User

Untitled

a guest
May 21st, 2015
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. angular.module('auth')
  2. .factory('ValidationService', ['$http', '$q', function($http, $q){
  3. var vs = {};
  4. vs.uniqueEmail = function(mail) {
  5. return $http.post('/api/user/validate/email/', {email: mail})
  6. .then(
  7. function(response) {
  8. if (!response.data.isValid) {
  9. alert(response.data.error);
  10. $q.reject(response.data.error);
  11. }
  12. return true;
  13. },
  14. function(response) {
  15. return $q.reject("OOPS");
  16. }
  17. );
  18. };
  19. return vs;
  20. }]);
  21.  
  22. angular.module('auth')
  23. .directive('uniqueEmail', function(ValidationService) {
  24. return {
  25. require: 'ngModel',
  26. link: function(scope, elm, attrs, ctrl) {
  27. ctrl.$asyncValidators.uniqueEmail = function(modelValue, viewValue) {
  28. var value = modelValue || viewValue;
  29. return ValidationService.uniqueEmail(value);
  30. };
  31. }
  32. }
  33. });
  34.  
  35.  
  36. <form novalidate class="css-form" name="usrform">
  37. Email: <input type="email" ng-model="user.email" name="email" unique-email required/><br/>
  38. <span ng-show="usrform.email.$touched && usrform.email.$error.uniqueEmail">addres is already in use</span>
  39. </form>
  40. <pre>email = "{{usrform.email.$valid}}"</pre>
Advertisement
Add Comment
Please, Sign In to add comment