Home › Forums › Front-end Issues › Ajax submit (checkbox) › Reply To: Ajax submit (checkbox)
Here the solution. I see the solution in other question from that foro.
Js file:
function AjaxSubmit() {
// initialize the acf script
acf.do_action('ready', $('body'));
// will be used to check if a form submit is for validation or for saving
let isValidating = false;
acf.add_action('validation_begin', () => {
isValidating = true;
});
acf.add_action('submit', ($form) => {
isValidating = false;
});
$('.acf-form').on('submit', (e) => {
let $form = $(e.target);
e.preventDefault();
// if we are not validating, save the form data with our custom code.
if( !isValidating ) {
// lock the form
acf.validation.toggle( $form, 'lock' );
$.ajax({
url: window.location.href,
method: 'post',
data: $form.serialize(),
success: () => {
// unlock the form
acf.validation.toggle( $form, 'unlock' );
}
});
}
});
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.