Home › Forums › Front-end Issues › ACF + Ajax; certain JS functionalities missing › Reply To: ACF + Ajax; certain JS functionalities missing
Situation & Problem
I’m implementing a custom admin page that gets ACF fields based on a selection.
Everything is working fine, including the showing and saving of the fields.
However, after a field is loaded using Ajax, certain JavaScript functionalities are not working:
return a.apply(b || this, c.concat(e.call(arguments)))
Am I maybe supposed to perform a JavaScript call to initialise the newly loaded fields? Or is there something wrong with my implementation of ACF?
Info on my implementation
Initial page load
On initial page load I run acf_enqueue_scripts();
to load all ACF scripts/styling.
Getting fields with Ajax
On the page when a selection is made, an Ajax call is made to a custom route which performs the following to get the fields HTML:
// get fields based on group key received from POST request
$fields = acf_get_fields(['key' => $key]);
// render fields, and use output buffering to catch the HTML
ob_start();
acf_render_fields($fields, 'my-page');
$fields_html = ob_get_contents();
ob_end_clean();
return $fields_html;
Which successfully returns the required HTML to the page.
Saving Fields
I very simply perform a POST with all the fields to a route which performs the acf_save_post('my-page')
function.
This function gets the fields from the request and saves them, which works wonderfully.
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.