Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

force asyncvalidators in angularjs

Tags:

angularjs

My problem - there is a web page which is accessible to all. If unregistered user comes in and saves the form on submit there is a login modal which asks for login.

If user is new he will registrate and press submit once again. If user is not new he will login and press submit once again.

If registered user visits the page form name is being validated with async validator:

app.compileProvider.directive('nameAvailable', ['$q', '$http', 'service', function ($q, $http, service) {
        return {
            restrict: 'AE',
            require: 'ngModel',
            link: function ($scope, elem, attrs, ngModel) {
                ngModel.$asyncValidators.queryName = function (queryName) {
                    --logic
                }
            }
        }
    }]);

And if registered user has this form saved with the same name then it will fail if he fills it and then log in.

Question is - how can I force validation on that field after user logs in?

One thing which I found is to use ngModelController and call validate(), but where to access it in my controller?

Thank you!

like image 586
sandris Avatar asked Sep 28 '22 20:09

sandris


1 Answers

I have created the plunker with sample how to validate async data in angular way.

Here updated plunker with validate button.

like image 115
Mikalai Avatar answered Nov 15 '22 11:11

Mikalai