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

  • 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');
    
    
  • 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)

The topic ‘my_acf_load_field – dynamic values every time’ is closed to new replies.