AngularJS Username Already In Use Example Directive

AngularJS Username Already In Use Example Directive   
 #AngularJS

  • then(function (unique) { //Ensure value that being checked hasn’t changed //since the Ajax call was made if (currentValue == element.val()) { console.log(‘unique = ‘+unique); ngModel.
  • $setValidity(‘unique’, unique); } }); }); } } }); //Ensure value that being checked hasn’t changed //since the Ajax call was made

  • public function isUniqueValue() { $id = Input::json(‘id’); $property = Input::json(‘property’); $value = Input::json(‘value’); $user = $value)->get(); $result = (count($user) == 0); return Response::json(array( ‘error’ => false, ‘isUnique’ => $result ), 200 ); } //checks if a value is unique for a field in the users table.

So this is how you can use ajax validation with an AngularJS directive to check if a username is already in use (by another registered user).

@kellenbrantley: AngularJS Username Already In Use Example Directive
#AngularJS

That’s pretty much it.

     < p class = "help-block" ng-show = "signup_form.email.$error.required" > Email is required . < / p >

     < p class = "help-block" ng-if = "signup_form.email.$error.email" > Must be a valid email . < / p >

       ng-unique = “{key: ‘users’, property: ‘username’}”

     < p class = "help-block" ng-show = "signup_form.username.$error.required" > Username is required . < / p >

     < p class = "help-block" ng-if = "signup_form.username.$error.minlength" > Must be at least 5 characters . < / p >

     < p class = "help-block" ng-show = "signup_form.username.$error.unique" > Username is already taken . < / p >

  

AngularJS Username Already In Use Example Directive

You might also like More from author

Comments are closed, but trackbacks and pingbacks are open.