Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Email/ID duplicate check in Angularjs

In Sign up form, I wanna make Duplication check. When is duplicated, A message is shown below the input box.

<div class="form-group">
  <label class="col-md-2 control-label"><strong>Email</strong></label>
  <div class="col-md-10">
     <input type="email" class="form-control" name="usr_Email" 
            ng-model="usrEmail" ng-keyup="checkDuplicate()">
     <span class="help-block" 
           ng-show="signupForm.$submitted || signupForm.usr_Email.$touched">
        <div ng-show="?????" class="text-danger">is duplicated!</div>
     </span>
     </div>
</div>

to check duplicate, I got counting number from server

$scope.user.usrEmail = $scope.usrEmail;         
var req = {
        method: 'POST',
        url: './api/v1/public/checkDuplication',
        dataType: 'json',
        headers: { 
            'Content-Type': 'application/json; charset=utf-8'
        },
        data: angular.toJson($scope.user)
    };

$http(req).success(function(data, status, headers, config){
    $log.debug($filter('json')(data));
    if(data.number == 0){
        ???????
    }
    else{
        ???????????????
    }

I'm very confused about what I should write in '???'

In advance, thanks!

like image 589
zzangs33 Avatar asked Dec 07 '25 05:12

zzangs33


1 Answers

Controller:

if(data.number == 0){
    //If email id is duplicate, then show the message in UI
      $scope.isDuplicate = true;    
} else{
   //If email id is not duplicate, then hide the message in UI
     $scope.isDuplicate = false;
}

HTML:

<div ng-show="isDuplicate" class="text-danger">is duplicated!</div>

I have used isDuplicate scope variable to show the message.

like image 135
Sangram Badi Avatar answered Dec 08 '25 18:12

Sangram Badi