Skip to content
This repository has been archived by the owner on Nov 24, 2018. It is now read-only.

I have a remote validation rules, but do not know how to display error messages returned from the server #56

Closed
kernnel opened this issue Jan 14, 2015 · 1 comment

Comments

@kernnel
Copy link

kernnel commented Jan 14, 2015

my code

app.factory('remoteValidator', ['valdrUtil','$http', function (valdrUtil,$http) {
    return {
        name: 'remote',
        validate: function (value,constraint) {
            var url = constraint.url,
                field = constraint.field,
                mydata = {};
            mydata[field] = value;
            $http.post(url, mydata).
                success(function(data) {
                    //TODO something,i need show message in html
                }).
                error(function(data) {
                    //TODO something
                });
            return valdrUtil.isEmpty(value);
        }
    };
}]);
@philippd
Copy link
Collaborator

valdr does not yet support asynchronous validators. I created a new issue (#57) to implement this feature.

Until then I would suggest to implement a custom validation directive.

Check the docs here:
https://docs.angularjs.org/api/ng/type/ngModel.NgModelController#$asyncValidators

and an example implementation here:
https://weblogs.asp.net/dwahlin/creating-custom-angularjs-directives-part-7-%E2%80%93-creating-a-unique-value-directive-using-asyncvalidators

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants