Home › Forums › Add-ons › Flexible Content Field › Populate Flexible Content Rows Programmatically › Reply To: Populate Flexible Content Rows Programmatically
Hi @circlecube
The flexible content field will create a random ID for the newly generated layout, so it will be hard to target it. What you can do is using the append action mentioned in this page: https://www.advancedcustomfields.com/resources/adding-custom-javascript-fields/.
I think you can also target the last layout after adding the new layout. This is what I tested in the console:
jQuery(".acf-field-1234567890abc .layout[data-layout='my_layout_name']:last input[id$='field_abc1234567890']").val("test")
Where “acf-field-1234567890abc” is the flexible content and “field_abc1234567890” is the custom field in the layout.
I hope this makes sense.
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.