I'm using acf_form to edit my WP posts with ajax. I've got it setup and working correctly in that I can edit the post and submit the new data without page refresh. I can then also load the new content without page refresh on success of this.
However, any JS in the acf form is not working once it's reloaded. How can I get this working, here is what I have so far
(function($) {
//// This saves without reloading the page
var pathtopage = window.location.pathname;
acf.do_action('ready', $('body'));
$("#content").on("submit", "#myform", function(e) {
e.preventDefault();
});
acf.add_action('submit', function($form) {
$.ajax({
url: window.location.href,
method: 'post',
data: $form.serialize(),
success: function(data) {
//// Attempting to reinitialise the JS in the form
$(document).trigger('acf/setup_fields', $('#myform'));
acf.validation.toggle($form, 'unlock');
//// reload the content and the edit form ready to go again
$('#content').load(pathtopage + ' #content');
}
});
});
})(jQuery);
In the documentation it states "place the following inline JS in the appended HTML, or run the JS on complete of your AJAX append. This will allow ACF to initialize the fields within the newly added HTML."
<script type="text/javascript">
(function($) {
// setup fields
acf.do_action('append', $('#popup-id'));
})(jQuery);
</script>
But, I can't figure out how to include this within my setup because I'm not using a popup I;m just reloading the form. Any help greatly appreciated.