Home › Forums › Front-end Issues › Adding a sub field to a repeater with JavaScript › Reply To: Adding a sub field to a repeater with JavaScript
@pzh20 , @hube2 I’ve just played around repeaters in JS.
Here the basic code used to add a row and to retrieve all the sub fields.
// Get repeater field (replace my-repeater-field-key' with a field key)
repeater = acf.getField('my-repeater-field-key');
// Add a new row
$row = repeater.add();
// Get subfields
let sub_fields=[];
$row.children('td.acf-field').each((i,$el)=>{
sub_fields[i] = acf.getField($el);
})
// show sub fields
console.log(sub_fields);
// loop around sub fields and populate them.
Not so tricky with ACF JS API…
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.