I’m pretty new to ACF, but I think it’s really awesome… I need some help, though, realizing a project for a customer.
I’m trying to populate a select field using values from a list, the options page, or something along the lines. Best would be an options page, since my customer could then add their own values.
Now, based on the selection the user has made, it should then display a couple text fields that are also populated by a list or something along the lines.
The select field should be a list of locations:
The text fields should be addresses:
123-ZIPCODE, City, Street
The important part is, I don’t want to change the field_id, it should always be the same, so the content of the text fields should dynamically change based on the selection the user has made.
I know I can show fields based on a selection the user has made, but I really don’t know how to do this dynamically.
I’ve read in your forums, but I have never done anything using AJAX before. Also, the examples given by John Huebner’s GitHub page are for returning data from users of posts, which in my opinion, is a very different thing from what I’m trying to do.
I just want to display different information about the location based on the choice the user made.
Location 1 = 3396 Church Street, Queens, NY 11423
Location 2 = 1965 Lawman Avenue, Chantilly, VA 22021
Location 3 = 2618 Locust Street, Nashville, GA 31630
Location 2 gets selected – now the user should see the data of Location 2 in 3 fields.
How do I accomplish this?
I hope you can help me. Thanks in advance.
Hello @wbjkr and welcome to ACF.
I have published several examples other than the one you mention. https://github.com/Hube2/acf-dynamic-ajax-select-example. While there is nothing exactly like what you’re looking for, what you want combines what is in the select example https://github.com/Hube2/acf-dynamic-ajax-select-example/tree/master/dynamic-select-example and the relationship example https://github.com/Hube2/acf-dynamic-ajax-select-example/tree/master/dynamic-fields-on-relationship.
The only real difference from any of the examples will be in the PHP function that runs on the ajax request. In this case you’ll be getting values from the options page to return.
I don’t have time at the moment to put any code together for this.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
© 2023 Advanced Custom Fields.