I am using Bootstrapvalidation to check my input fields. On top of that, I have additional check that is done on submit. It's either submitted without showing errors or, when I use this:
$("#form").submit(function(ev){
ev.preventDefault();
});
$("#submit-form").on("click", function(){
var valid=some code for additional check;
if (valid) {
$("#form").submit();
}
else {
return;
}
});
But then it's just all recursive and the form doesn't get submitted. How to I get this to work?
@Harshil's answer covers the bootstrapValidation plugin which is totally a different plugin then 1000hz BootstrapValidator plugin
In your approach, you have ev.preventDefault();
in first script which is separate script and preventing the form to submit doesn't matter the input fields / additional check are valid or invalid and the input states / additional check valid or invalid not defined in first script at all.
what you need is Conditionally handling the submit event to check and handle the additional custom check
along with other form input fields to validate and if all good, submit the form,
$('#form').validator().on('submit', function (e) {
if (e.isDefaultPrevented()) {
// handle the invalid form...
} else {
// everything looks good!
}
})