Support

Account

Forum Replies Created

  • I’m running into the same issue. There’s no clear indication of this behaviour in the documentation or on these forums / StackOverflow.

  • @neurodesigns your little function is just perfect, and is exactly what was missing. Thank you!

    I was just leaving the labels blank before but that gets confusing quickly. This should definitely be incorporated into the plugin.

  • Alright, thanks for confirming this. I may get into some custom JavaScript at some point, but this particular field is mostly read-only, and for now can be set when saving the post.

    For future readers, I ended up making the field read-only when set to null, and then hooking into update_value to generate unique values there. I set the placeholder text to “Automatically generated on save”. Not the most elegant solution, but it works!

    function my_acf_generate_file_url($value, $post_id, $field) {
    
    	if ($value == NULL) {
            
            // generate GUID unique to each row of the repeater and it's value
    		$data = openssl_random_pseudo_bytes(16);
    		$data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set version to 0100
    		$data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits 6-7 to 10
    		$value = vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
    	}
    
    	return $value;
    }
    add_filter('acf/update_value/key=field_xxxxxxxx', 'my_acf_generate_file_url', 10, 3);
  • Hi John,

    Thanks for the info.

    I may have phrased my question ambiguously, or perhaps not understood your response, but I’m not looking to generate rows in a repeater with values. I’m looking to have one of the values of a repeater pre-populated with a value generated in the back-end, which I can do with ‘load_value’ for the first row, but I’m looking to have all subsequent rows, no matter the number the user chooses, each have a unique value generated and pre-populated with each new row that may be added.

    Looking through the available hooks, I’m thinking now that this may lie more in the JavaScript domain, as there may not be any way to hook into each new row when a user adds it, as that’s probably not even a back-end process.

    Any further guidance on this would be greatly appreciated 🙂

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