What I’d like is to be able to have one true/false field in a repeater field be set to true.
So I would need to check all rows and return the validation based on the count:
function my_acf_validate_value( $valid, $value, $field, $input_name ) {
// Bail early if value is already invalid.
if( $valid !== true ) {
return $valid;
}
if (count_of_sub_field_value == 0) {
return __( 'One field has to be true.' );
}
if ( count_of_sub_field_value > 1 ) {
return __( 'Only one field can be true.' );
}
return $valid;
}
add_filter('acf/validate_value/name=sub_field', 'my_acf_validate_value', 10, 4);
How would do that?
TIA
I know it’s been a while now, but did you ever figure this out. I’m trying to do something similar, but I’m having a difficult time with it.
Sort of. I didn’t get it to work with the actual field validation but I was able to write some js that will show an alert if the fields aren’t what I want them to be.