Support

Account

Home Forums Backend Issues (wp-admin) my_acf_load_field – dynamic values every time

Solved

my_acf_load_field – dynamic values every time

    • enky

    • March 13, 2019 at 10:02 pm

    Hi,

    is it possible to populate a textfield inside a repeater, but every time i add a row, the value is different.

    Right now, the value is the same, every time i add a row.

    
    function my_acf_load_field( $field ) {
      $rndnumber = random_int(100, 999);
      $field['default_value'] = $rndnumber;
      return $field;
    }
    
    //field_5c88dd5d00e5c is the textfield inside the repeater
     add_filter('acf/load_field/key=field_5c88dd5d00e5c', 'my_acf_load_field');
    
    
    • enky

    • March 13, 2019 at 11:19 pm

    Ok, got it. You do it via the JS Hooks 🙂

    acf.addAction('append_field/key=field_5c88dd5d00e5c', append_field);
    
    function append_field($el){
      $el.val(Math.random());
      $el.disable();
    }
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.