I am using data attributes for jQuery Validation plugin. I need to use the "remote" validation function, however, I need to modify the data being sent to the remote location depending on the form it is used on. I want to use data attributes and not create a <script>
call for each form.
I created a custom $.validator.addMethod
to handle this, but every time I run it, the form comes back like it is returning false
. I added a call to console.log()
to make sure that the data is returning either true
or false
based on the remote script and it is. It returns true
when it should and false
when it should.
Here is my custom addMethod:
$.validator.addMethod("dupcheck", function(value,element){
var method = element.getAttribute("data-method");
var data = { "dupcheckv" : value, "dupcheckm" : method };
$.post( "duplicate-check.php", data).done(function(response){
console.log(response);
return response;
});
});
I did take a look at how to make a jquery “$.post” request synchronous [duplicate]
, but async:false
is deprecated so that doesn't help.