Support

Account

Home Forums Front-end Issues ACF Form Repeater Populate

Solved

ACF Form Repeater Populate

  • Greetings all!

    I’m rendering a form on a page and I need to populate a repeater field with localStorage data.
    What’s the best approach to achieve this?

    Thanks.

  • Hi @bmds,

    Since localstorage is Javascript-based you don’t really have much choice but to read the localstorage data and create new rows and insert the values.

    Since it’ll be very hard for you to replicate how the rows are structured I’d recommend just triggering the “add row” button with JS thus letting ACF do the creation.

    Something like:

    
    jQuery('.acf-repeater-add-row').trigger('click', function(){
    
    //Delay a function a few hundred millseconds to give ACF time to create the row then do your own insertion. Preferably via function call
    setTimeout(insertLocalstorageData,500)
    
    });
    
    function insertLocalstorageData(){
    //Do stuff!
    
    }
    
  • Hi @jonathan!

    Thanks for your help.
    That is what I had in mind and I did look at “acf-pro-input.js” trying to understand how to trigger the click.
    I’ve tried this in the console for a quick test but no rows are added

    jQuery('.acf-repeater-add-row').trigger('click')

    Thoughts?

  • Did some research and this works

    $('.acf-repeater-add-row')[0].click();

    Thank you!

  • You’re welcome and good luck!

    My guess is that there’s more elements using the same class but perhaps only one link. So this might work too
    $('a.acf-repeater-add-row').click();

    Just as a note 🙂

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘ACF Form Repeater Populate’ is closed to new replies.