Answer the question
In order to leave comments, you need to log in
How to return value from asynchronous ajax request for jQuery Validation plugin required method?
I'm using the jQuery Validation plugin (JVP) to validate forms through ajax requests to the server. Everything works fine except for one thing: JVP does not remotely validate empty fields.
I don't mind using the plugin's default rule required
without requests to the server, but I would like to implement such a validation. Yes, and I want to solve the problem)
So, the problem is: JVP does not validate empty fields through its built-in remote
. But I can use functions in its required
method:
required: function(element) {
return true_or_false;
}
validate_url = '/emails/validate'
required_validate = (e, callback) ->
data = {}
data[e.name] = $(e).val()
$.ajax(
url: validate_url
type: 'post'
dataType: 'json'
data: data
success: (response) ->
callback(response)
)
$('#my_form').validate(
rules:
'email[email]':
required: (element) ->
required_validate(element, (response) ->
if response == true || response == "true"
false
else
true
)
)
required
JVP method does not wait for a response from the server and receives it true
earlier. Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question