Support

Account

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…