Home › Forums › Front-end Issues › ACF + Ajax; certain fields not initialising
Situation
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.
Problem
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.
For example these are a few fields that are being received.
The radios work just fine, but the add row
button does nothing.
Here is a text field, and the error in the console that’s shown when Visual
is clicked.
You must be logged in to reply to this topic.
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!
Are you building WordPress sites with ACF and @BeaverBuilder, and wanted to use your ACF Blocks in both the block editor and Beaver Builder?
— Advanced Custom Fields (@wp_acf) May 10, 2023
The BB team recently added support for using ACF Blocks in Beaver Builder. Check it out 👇https://t.co/UalEIa5aQi
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.