5

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!

1
  • Did you try using form.$submitted, to check if the form has been submitted and do the logic you need after that? Commented May 27, 2015 at 15:16

1 Answer 1

4
+50

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

Here updated plunker with validate button.

Sign up to request clarification or add additional context in comments.

1 Comment

That is the same what I have - I need that near the input field which has button, which runs async validation one more time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.