• Resolved awjensen

    (@awjensen)


    I want to make the current field required or not required depending on the value in a taxonomy field.

Viewing 1 replies (of 1 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback! You could probably achieve that using the native filter acf/validate_value. See documentation.

    Usage example:

    add_filter('acf/validate_value/name=my_text', 'my_text_field_validate', 10, 4);
    function my_text_field_validate($valid, $value, $field, $input_name){
        
        // retrieve $_POST['acf']
        $acf = acf_maybe_get_POST('acf', array());
        
        // get taxonomy field using key and force it to array
        $taxonomy = acf_maybe_get($acf, 'field_6100f527ff385');
        $taxonomy = acf_get_array($taxonomy);
        
        // if current value is empty and the Term ID 7 is in the taxonomy field
        if(empty($value) && in_array(7, $taxonomy)){
            
            // return an error
            $valid = 'This field is required';
            
        }
        
        // return
        return $valid;
        
    }
    

    Video demo: https://i.imgur.com/JI7aWAx.mp4

    Hope it helps!

    Have a nice day!

    Regards.

Viewing 1 replies (of 1 total)
  • The topic ‘Change required setting based on taxonomy field’ is closed to new replies.