Support

Account

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.