Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions acfAjax.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
//listens to all acf_forms on page.
jQuery(function($) {
acf.add_filter('validation_complete', function( json, form ) {
if( !json.errors ) {
if( !json.errors ) {
//if no errors stop form from being submitted.
form.submit(function(event) { event.preventDefault(); submitACF_AJAX(this); return false;});
}
}
return json;
});

//sends the request using FormData object will work with file uploads as well.
function submitACF_AJAX(form) {
var data = new FormData(form);
$.ajax({
var data = new FormData(form);
var $spinner = $("#acf-form").find('.spinner, .acf-spinner');
$.ajax({
type: 'POST',
url: window.location.href,
data: data,
processData: false,
contentType: false
})
.done(function(data) {
$(form).trigger('acf_submit_complete', data);
contentType: false,
beforeSend: function(data){
acf.showSpinner( $spinner );
}
})
.fail(function(error) {
.done(function(data) {
$(form).trigger('acf_submit_complete', data);
acf.hideSpinner( $spinner );
})
.fail(function(error) {
$(form).trigger('acf_submit_fail', error);
});
}
Expand Down