how to use remote inside form.validate
Closed this issue · 8 comments
please help
$scope.signupsub=function(signup){
if(signup.validate({
rules: {
mobile: {
remote: {
url: data+'ajaxcall/mobilechechkuser',
type: "post"
}
},
email: {
remote: {
url: data+'ajaxcall/emailchechkuser',
type: "post"
}
}
},
messages: {
mobile: {
remote:"mobile number already exit"
},
email: {
remote:"email already exit"
}
}
})){
alert();
}
}
remote url is calling but not showing error
thanks
pls help some body
Hi! I think it has something to do with the serverside response you're returning from the ajaxcall
endpoints.
From the docs:
The serverside response must be a JSON string that must be
true
for valid elements, and can befalse
,undefined
, ornull
for invalid elements, using the default error message. If the serverside response is a string, eg. "That name is already taken, try peter123 instead", this string will be displayed as a custom error message in place of the default.
See http://jsfiddle.net/9ruhmex0/ for a working example.
its not working inside validate() function but its working like this
$scope.validationOptions = {
rules: {
email: {
required: true,
remote: {
url: '/echo/json',
type: 'post',
data: {
json: 'false'
}
}
}
}
};
Ah, I see. That's because the if statement is synchronous and the remote call is asynchronous. The solution is indeed to pass the validation options into the ng-validate
directive, instead of the validate()
method.
can you tell how
$scope.validationOptions this one?
Yes, $scope.validationOptions
is the way to go!
thanks