I am using foundation with abide validation and I am trying to make a custom validator to check if an email entry already exists in our database. However, I can't seem to be able to change the value of the valid variable from true to false inside the if else statement. It always returns true, even when the alert "it doesn't work" successfully launches.
$(document).foundation({
abide: {
live_validate: false, // validate the form as you go
validate_on_blur: false,
patterns: {
positive_price: /^\+?[0-9]*\,?[1-9]+$/,
},
validators: {
emailVerification: function(el, required, parent) {
var email = el.value,
ajax = 1,
valid = true;
$.ajax({
type: "GET",
url: "/check.do?action=userEmailAvailable",
data: "userEmail1=" + email + "&ajax=" + ajax,
success: function(data) {
if (data.result == 1) {
alert("it works");
valid = true;
} else {
alert("it doesn't work");
valid = false;
}
}
});
return valid;
}
}
}
});