Home Forums General Issues Using acf/validate_value to validate repeater field Reply To: Using acf/validate_value to validate repeater field

  • although this is old, for those who look for a good solution for this issue of validating the first row’s fields in a repeater, here is what I just figured out:

    //validate first step
    add_filter('acf/validate_value/key=field_57bc841e7f973', 'itamar_acf_validate_value__fs', 10, 4);
    function itamar_acf_validate_value__fs( $valid, $value, $field, $input ){
    	// bail early if value is already invalid
    	if( !$valid ) {
    		return $valid;
     	// load data
    	$repeater_field = $_POST['acf']['field_57bc841e7f973']; //repater parent key
    	reset($repeater_field); //reset repeater array to the rist row
    	$first_field = key($repeater_field); //get first key in the repeater array
    	$my_text_field = $_POST['acf']['field_57bc841e7f973'][$first_field]['field_57bc8a5447d06']; //specific field
    	$characters = mb_strlen($my_text_field, 'utf-8');
    	if ( $characters < 100 ) {
    		$valid = 'כתבת '.$characters.' תווים בלבד בתוכן השלב הראשון. עליך לכתוב לפחות 100 תווים.';
    	// return
    	return $valid; 

    in this case the validation is for a specific field under the first row in a specific repeater. you can change the characters count to 1 and then you get a real “required” field.