Home › Forums › General Issues › Auto populated sub_field in repeater.
I have been trying for last few days, no luck. Below is the issue.
Scenario ( CPT and backend based site ):
repeater_field
row 1 > sub_field-1 — sub_field-2
row 2 > sub_field-1 — sub_field-2
row 3 > sub_field-1 — sub_field-2
and so on…one can add as many rows he wants
What I wish to achieve
Automatically fetch value from sub_field-2 and load it in sub_field-1 with some modification
So for example a user enters in sub_field-2 ….’london’
Automatically or after saving post sub_field-1 should show…. ‘domain.com/?city=london’
Please someone help.
I have tried to implement all types of solution
https://support.advancedcustomfields.com/forums/topic/acf_form-populate-flexible-field-content/
https://support.advancedcustomfields.com/forums/topic/dynamically-populate-repeater-field-2/
But I cant just figure out.
You can try to build something in JavaScript to do it on the page. That would be too much code to post here but I can give you the general steps. You need to
1) build an action that fires on the keyup action of the first field
2) Get the value
3) get the closes repeater repeater = e.$el.closest('.acf-repeater')
4) Then locate the sibling field repeater.find('[data-key="field_12345678"] .acf-input input')
5) adjust the value an insert it into the other field
The other option is to do it when the post is saved. See acf/save_post https://www.advancedcustomfields.com/resources/acfsave_post/. Get the values from the repeater and use https://www.advancedcustomfields.com/resources/update_row/ to update the other field.
If I can pull this off it will be awesome. Also for the community. I wonder how come no one ever tried.
Every case of using custom JS for fields is pretty specific to what needs to be done and it’s really complicated to do anything generic. Every type of field needs different handling and that handling can be completely different when a field is in a repeater vs not in a repeater. Someone could make a full time job out of writing tutorials for it. I have some examples of getting and updating values with JS here https://github.com/Hube2/acf-dynamic-ajax-select-example might give you an idea of what’s involved.
The topic ‘Auto populated sub_field in repeater.’ is closed to new replies.
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.