Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- angular.module('auth')
- .factory('ValidationService', ['$http', '$q', function($http, $q){
- var vs = {};
- vs.uniqueEmail = function(mail) {
- return $http.post('/api/user/validate/email/', {email: mail})
- .then(
- function(response) {
- if (!response.data.isValid) {
- alert(response.data.error);
- $q.reject(response.data.error);
- }
- return true;
- },
- function(response) {
- return $q.reject("OOPS");
- }
- );
- };
- return vs;
- }]);
- angular.module('auth')
- .directive('uniqueEmail', function(ValidationService) {
- return {
- require: 'ngModel',
- link: function(scope, elm, attrs, ctrl) {
- ctrl.$asyncValidators.uniqueEmail = function(modelValue, viewValue) {
- var value = modelValue || viewValue;
- return ValidationService.uniqueEmail(value);
- };
- }
- }
- });
- <form novalidate class="css-form" name="usrform">
- Email: <input type="email" ng-model="user.email" name="email" unique-email required/><br/>
- <span ng-show="usrform.email.$touched && usrform.email.$error.uniqueEmail">addres is already in use</span>
- </form>
- <pre>email = "{{usrform.email.$valid}}"</pre>
Advertisement
Add Comment
Please, Sign In to add comment