• Hello,

    I need a fix on my ACF conditional fields. 

    Here is a scenario
    Location (field)
    – Radio Button A – (Remote)
    – Radio Button B – (States)

    When “Radio Button B” is selected > Field C (Checkbox – List of 50 US States) is displayed. 

    The problem starts when the user who selected “Radio Button B” and changed is mind and selects “Radio Button A”: all the selected states in “Field C” are still checked on the admin area and displayed on the frontend. 

    Goal: When user switches back from “Radio Button B” to “Radio Button A” all the value in “Field C” must be cleared/reset.

    I want ACF fields to reset all the fields displayed conditionally if the condition is no longer true. Can your plugin do that?

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

    (@hwk-fr)

    Hello,

    Thanks for the feedback!

    What you’re describing is the native ACF behavior. The ACF Conditional Logic simply hide fields on screen, but doesn’t delete “hidden” values. ACF only delete metadata in some very specific cases, but not with Conditional Logic.

    If you want to clear these unwanted values, you could hook on the acf/save_post action (see documentation). This action is triggered each time a post/user/term/options page is saved. And then cleanup the meta field based on your condition using delete_field() (See documentation).

    Here is a usage example:

    add_action('acf/save_post', 'my_acf_save_post', 15);
    function my_acf_save_post($post_id){
        
        // get radio_buttons field value
        $radio_buttons = get_field('radio_buttons', $post_id);
        
        // if condition is met
        if($radio_buttons === 'value_a'){
            
            // delete field_c field value
            delete_field('field_c', $post_id);
            
        }
        
    }

    Hope it helps!

    Have a nice day!

    Regards.

Viewing 1 replies (of 1 total)
  • The topic ‘Reset or Clear Field Value Based on Condition’ is closed to new replies.