Question: how to delay the submit event and run code when valid?
Closed this issue · 1 comments
richardvenneman commented
We need to run some code when a form is valid (showing an element in the DOM). The strategy is to stop the form submit event in a listener when the form is valid, insert the element in the DOM or update styles, remove the listener and resubmit the form.
If I understand correctly from reading this function, the form is automatically submitted when the form isValid()
: https://github.com/formapro/JsFormValidatorBundle/blob/master/Resources/public/js/fp_js_validator.js#L260.
jsFormValidator is initialised like this:
$(function(){
$('#bookingpage form').jsFormValidator({
onValidate: function(errors, event) {}
});
});
Unfortunately the form submit cannot be stopped from executing with code like this:
$('#bookingpage form').on('submit', function (e) {
e.preventDefault();
e.stopPropagation();
// Or
return false;
});
How can we ensure the form is not submitted when it is valid?