I had trouble implementing parsley.remote.js because of AMD in our require configuration.
I'm trying to implement a custom validator that does an AJAX request and returns true or false based on the response.
Problem is, I keep getting a response of false regardless of what the AJAX request returns.
Why does this code never work?
window.ParsleyValidator.addValidator('cardcode',
function (value) {
var valid = false;
$.ajax({
url: '/data/checkout/cvvCheck.json',
data: {
cvv: value
},
success: function(response) {
if(response.valid === true) {
return true;
}
else {
return false;
}
}
});
}, 32);
<input type="tel" name="card-code" id="card-code" maxlength="4" required="" data-parsley-required="true" data-parsley-required-message="Please enter the cvv" data-parsley-type="number" data-parsley-type-message="Please enter a valid cvv" data-parsley-cardcode="true" data-parsley-cardcode-message="Please ensure you are entering the correct cvv." data-parsley-id="65">