Home Forums General Issues Synchronize fields


Synchronize fields

  • I’m struggling with getting this simple (or what I think is simple) code to work with ACF. I normally code forms in PHP/JS but trying my hand at WP and now ACF. Can this be done?

    I want to sync 2 form fields. So whatever is typed into Field 1 is automatically input into Field 2 (preferably in real-time). This is baby steps, my real goal is to eventually have the output in Field 2 perform some sort of math on Field 1, but crawl before walk. The code I’d use in JS would something like:

    $("field_1").on("input", function() {

    Anything like this possible in ACF?

  • Yes, but you need to use bigger selectors. Look at the DOM of the acf field.

    $('#field_XXXXXXXX .acf-field input');

    or you can use the ACF JS API

  • Thank you John. I’m still struggling to get it work, but will fiddle around and when I figure it out get back to this thread.

  • I sometimes use the ACF JS API but sometimes I do not. It really depends on what I’m doing. But in many cases it’s easier to get and set values with the API because it takes care of all the little details in the more complex fields.

    I have not figured out how to deal with nested fields in repeaters using the API, but I have not really had the need to do that.

  • Finally figured it out and your explanation above was the answer. Thank you again.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.