Support

Account

Home Forums Add-ons Flexible Content Field Populate select fields dynamically using JavaScript API Reply To: Populate select fields dynamically using JavaScript API

  • The issue is that the selected value is not available in the choices when the field is loaded and displayed. There needs to be two parts, the JS AJAX part that your using and a PHP part that creates the choices when the field is initially displayed.

    This can be accomplished by creating an acf/prepare_field filter. In this filter you can do 1 of 2 things.

    1. You can populate all of the field choices based on the value of the other field.
    2. At a minimum set at least one choice value based on the current value of the field and then repopulate all the values when by using adding a filter to the ready action in your java script.

    I generally opt for #1 because it is faster and easier to do this in php rather than make the extra AJAX request.