问题
I'm using parsley.js for validation. It does the job without using Ajax. But when I add a .submit() function, its always fired and does not wait for validation.
UPDATE: I need to use remote validation too
$(document).ready(function(){
$('#form_register').submit(function(){
alert('The form submitted');
})
});
https://jsfiddle.net/rostamiani/mzdvLpnt/3/
It works in fiddler but not in my page. The I attached my page: https://ufile.io/hm7w5
回答1:
UPDATE This code does not work for remote validation. When remote validation is used, isValid returns null!
I used isValid() function to check validation status at submit.
$('#form_register').submit(function(e){
// Prevent normal submittion
e.preventDefault();
// If the form is not submitted yet, skip
if (! $('#form_register').parsley().isValid()) {
return;
}
alert('The form submitted');
}
来源:https://stackoverflow.com/questions/51345227/submit-is-always-executed-even-when-parsley-validation-fails