Home › Forums › Backend Issues (wp-admin) › Populate Text Fields on Select Field Change › Reply To: Populate Text Fields on Select Field Change
Hi, that’s one of my examples.
You don’t need to create a plugin, you can add the code directly.
Basically there are 3 parts. There is the addition of the custom JavaScript file done on the acf/input/admin_enqueue_scripts
hook. This goes in your functions php file.
The second part is the custom JavaScript file that does the work of making the request and populating fields.
Then there is the PHP side of the AJAX request, this also goes into your functions.php file. My example is built as a class, just because I use OOP for just about everything.
The main difference here is that you need to know what row of the repeater you are on. You can get the row by using
var $row = e.$el.closest('.acf-row');
from there you can do a find to get each of the fields in the row
// this will depend on what type of field you're getting
var $field = $row.find('[data-key="field_xyz"] input');
Hope that is of some help.
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.