Home Forums General Issues Dynamically Populating fields based on other fields


Dynamically Populating fields based on other fields

  • Okay, so I think this will end up being more of a bug report, than an actual help request. I’m currently developing for a client, and 1 of my missions is to use ACF and the repeater fields, to achieve a form where you can dynamically add new rows, that each contain:

    A Text Box
    A State Select Box,
    A County-Multi Select Box
    and a Zip Select box.

    Now what I want to achieve, is have the County Box populate, based on the state selected in the State box. In addition, I want the zip list to populate, based on the Selections of counties menu.

    Now I’ve achieved this via jQuery, and multiple ajax calls. However, this seems like a messy way to achieve it, and means users without js(I realize it’s less than 2% but still) are unable to use the site.

    Now I’ve gone up and down and inside and out the code for both ACF (4.38 I believe) and the repeater plugin (newest version) and can not for the life of me find a way to achieve this without resorting to jQuery.

    At the very least, I believe you should be able to populate the fields, via the acf/load_field filter, but that doesn’t seem to pass any of the actual stored values. In addition, doing a call for the field data inside of the acf/loav_field filter causes the code to loop infintely.

    As well, there doesn’t seem to be any way of determining, in the load_field filter, which repeater row it’s currently in. In short, there seems to be literally no way, short of jquery, to pass the values of 1 field to another for population, which seems like a VERY major oversight.

    In my jQuery, how I find out what row I’m in I use the following jquery:

    var field_key = $(this).find(‘select’).attr(“name”);

    and in php

    $field_key = str_replace(“]”, “”, str_replace(“[“, “”, preg_replace(“/[a-zA-Z][a-zA-Z0-9_]*/”, “”, $_POST[‘field_key’])));

    which works, but again it just seems really hacky.

Viewing 1 post (of 1 total)

The topic ‘Dynamically Populating fields based on other fields’ is closed to new replies.