Support

Account

Home Forums ACF PRO Populate a subfield on-the-fly

Solving

Populate a subfield on-the-fly

  • Hello!

    You know the forms that exist on the Web where someone selects a “Country”, and then suddenly the “State/Province” field filters appropriately (originally starting as empty)?

    I want to achieve that with ACF. I have read throughout the Forums people asking for the same thing but it doesn’t seem to ever get resolved.

    I understand how to pre-populate a select field in general… I do it all the time. For example… I have an Options Page, where the Admin enters a series of “choices” and then I grab those “choices” on-the-fly to pre-populate a Select Field. That’s not what I am asking for here.

    More specifically…

    I have a CPT for “Products”…

    And, I have a CPT for “Race Tracks”. Each “Race Track” has 1 or more “Products” associated with it.

    Finally, I have a CPT for “Orders”.

    When creating a new Order, there is a Repeater Field that has 2 Select fields (Post Objects): Race Track, and Product.

    I want all the Race Tracks to show up in the list (and they do). Now… I initially want the “Products” to be empty. Only upon selecting a “Race Track” do I want “Products” to populate (with, of course only the “Products” associated with the selected “Race Track”).

    Please help!

    I want to do this *without* having to Save the post multiple times. I need AJAX for this… Or… is there a plugin in the wild with a “Filtered Post Object” field type perhaps that I could set conditions on? That’d be cool!

    I will keep looking, but just wanted to put this out in the mean time. I will post back if I find a solution. There has to be a straightforward solution to this very common problem.

    Thanks for your time,
    Keith

  • Hi @klock

    There’s an old tutorial for this kind of situation. You can check it out here: https://www.bobz.co/dynamically-populate-select-fields-choice-in-advanced-custom-fields/. Because it’s an old tutorial, you need to modify it to fit your needs and the current state of ACF.

    I hope this helps 🙂

  • Thanks James…

    I’ve spent many many hours with that link, trying to convert it to something that’ll work for my situation, with no luck.

    Things are *significantly* different when using Post Objects over a standard Select (a Select is what is being used on bobz.co).

    There HAS to be a simple to follow process, or something existing… this is such a common issue with ACF.

    Someone else… help???

    Thanks! 🙂

  • I am looking to do something similar to what you are trying to accomplish. I ended up stumbling upon this link to an example from a post in the forums. I hope this help.

    https://github.com/Hube2/acf-dynamic-ajax-select-example/tree/master/dynamic-select-example

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

The topic ‘Populate a subfield on-the-fly’ is closed to new replies.