Actually, to make the form work again after submitting it, $form.one
is better than $form.on
, so the e.preventDefault()
is only being triggered once:
/**
* Setup the ajax submit
*/
setupAjaxSubmit() {
acf.addAction('submit', ( $form ) => {
if( !$form.hasClass('is-ajax-submit') ) {
return true;
}
// only prevent the default of the submit action once:
$form.one('submit', (e) => {
e.preventDefault();
});
// my custom code for handling AJAX posting:
$form.acfFrontendForm('doAjaxSubmit');
});
}