Support

Account

Home Forums ACF PRO Pre Populate Textfield in Repeater

Solved

Pre Populate Textfield in Repeater

  • Hi Guys,

    I have a repeater that has three text fields inside itself.

    ONE of those textfields should be pro polulated by a random number.

    I used this code:

    function my_acf_load_value(   $field ) {
    	
    $field['default_value'] = md5(uniqid(rand(), true));
         return $field;
    }
    add_filter('acf/load_field/name=api-key', 'my_acf_load_value', 10, 3);

    Unfortunately (or as expected if you think about it) if you add 2 or more rows to the repeater in the backend, they all get the same random number. What I want is to generate a new number for each row the editor adds to the repeater.

    How can I accomplish this? Any idea?

    Thanks so much in advance Sascha

  • I think you need to loop through the repeater instead of applying it to the entire field.

  • Hi guys, John’s answer send me in the right direction. I did what the user benjibee said in that thread. It is totally fine for me to generate the keys on save and not on adding a new repeater! Thanks guys 😉

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

The topic ‘Pre Populate Textfield in Repeater’ is closed to new replies.