Guest User

Untitled

a guest
May 19th, 2015
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #### JS ##########
  2. angular.module('auth')
  3. .directive('uniqueEmail', function($http, $q) {
  4. return {
  5. restrict: 'A',
  6. require: 'ngModel',
  7. link: function(scope, elm, attrs, ctrl) {
  8. ctrl.$asyncValidators.uniqueEmail = function(modelValue, viewValue) {
  9. return $http.post('/api/user/validate/email/', {email: modelValue}).then(
  10. function(response) {
  11. if (!response.data.isValid) {
  12. return $q.reject(response.data.error);
  13. }
  14. return true;
  15. },
  16. function(response) {
  17. return $q.reject("oops, something going wrong!");
  18. }
  19. );
  20. };
  21. };
  22. }
  23. });
  24. ##### HTML ##########
  25. <form novalidate class="css-form" name="usrform">
  26. Email: <input type="email" ng-model="user.email" name="email" unique-email/><br/>
  27. <span ng-show="usrform.email.$error.uniqueEmail">addres is already in use</span>
  28. </form>
  29. <pre>email = "{{usrform.email}}"</pre>
Advertisement
Add Comment
Please, Sign In to add comment