I have a form and I'm trying to do parsley remote validation on one of the fields, however, on form validation, the form submits before it waits for a response from the remote function (via asyncValidate()). Thus, even when the field is invalid, it'll show the field error css but the form still submits.
I tried using a $.Deferrede object but this isn't working.
function add_remote_validation() {
var form = card.el.find('form');
$(form).parsley().addAsyncValidator('validate_function', function (xhr) {
return parseInt(xhr.responseText);
});
}
add_remote_validation();
card.cards['my_card1'].on('validate', function(card){
add_remote_validation();
var result = $.Deferred();
// test any asyncronous validation before doing regular validation
$(form).parsley().asyncValidate()
.done(function(){
var valid = $(form).parsley().validate();
if(valid) {
result.resolveWith(valid);
} else {
result.rejectWith(valid);
}
})
.fail(function(){
result.rejectWith(false);
});
});