Is there any way to "undo" the preventDefault()
method?
I have this little code that solves this, but I wanted to know if there is any more efficient way to do it.
var $form = $('form');
$form.data('working', false);
$form.data('canSubmit', false);
$form.submit(function (e) {
if (form.validations.form($form)) {
if (!$form.data('working')) {
$form.data('working', true);
if ($form.data('canSubmit')) {
// make the post here
} else {
e.preventDefault();
$.get(BASE + 'file.txt', function (response) {
var lastPartnerSent = response;
var nextPartner = '';
switch (lastEmailSent) {
case 'Empresa 1':
nextPartner = 'Empresa 2';
break;
case 'Empresa 2':
nextPartner = 'Empresa 3';
break;
default:
nextPartner = 'Empresa 1';
}
$('input.i_parceiro').val(nextPartner);
$form.data('canSubmit', true);
$form.submit();
});
}
}
} else {
$form.data('working', false);
e.preventDefault();
return false;
}
});
This happens because I have to read and write a file after doing the field validations and only after that make the post for the page. The post can not be done by ajax.
The question is basically whether you can divide that form into 3 steps, ie:
1st validate fields, eg name, email, etc. (synchronous)
3rd submit the form per post