Ng-minlength not working with custom validation

I'm working with angularJS, i'm trying to do a form where user type his username and application validate if it's available on database and his length is between 5/10 chars.

<input type="text" name="uname" ng-model="user.uname"
ng-minlength="5" ng-maxlength="10" uniqueusername required/>

Uniqueusername is a directive that check if username is available:

app.directive('uniqueusername', function($http){
return{
    require : 'ngModel',
    restrict : 'A',
    link : function(scope,elem,attrs,ctrl){
        ctrl.$parsers.unshift(function(value) {
            $http.get('/api/check'+value).success(function(data,status){
                if(data.available=='true'){
                    ctrl.$setValidity('unique',true);
                }
                else{
                    ctrl.$setValidity('unique',false);
.........................................................................

When i type an username with less than 5 chars, is valid. And this shouldn't happen. If I delete uniqueusername for input it work perfectly.

Thank for your answers.

Answers


you have to return a value from the parser function:

app.directive('uniqueusername', function($http){
    return{
        require : 'ngModel',
        restrict : 'A',
        link : function(scope,elem,attrs,ctrl){
            ctrl.$parsers.unshift(function(value) {
                $http.get('/api/check'+value).success(function(data,status){
                    if(data.available=='true'){
                        ctrl.$setValidity('unique',true);
                    }
                    else{
                        ctrl.$setValidity('unique',false);
                    }
                }
                return value;
            }
        }
    });

Need Your Help

How do you change a user password in a script with busybox and openssl?

linux openssl change-password busybox

I need to synchronize a user account and password to an external source on a system with busybox and openssl installed. When the external source tells my system to update credentials, how do I cha...