Well, it’s been a month on this topic, but I have recently been working on a project where I wanted to do this so I thought I would share my solution.
Take a look at this file I uploaded to GitHub https://github.com/Hube2/blunt-parametric-search/blob/master/admin/js/admin.js
Look at the function _para_meta_key_change.
This function gets a meta_key value from one of two possible fields. Depending on other values it then removes the current rows from a repeater field, then it does an AJAX request and re-populates the repeater with the values that in the AJAX response.
I can’t really explain the whole thing, it took me several hours of poking and prodding to figure it out.
The important bits:
line 128: triggering the click action for the add row link
lines 130 to 135: getting the
data-id, which is a unique ID for a cloned field that ACF adds, of each row that is added, and then setting the values of the fields in that row.
The setting of the values will be highly dependent on what type of field your setting, in my case these are simple text fields.
Also since your adding one field and then setting the values you won’t need a loop, you’ll just need to look at the last row, the one that was just added.
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!