AdvancedCustomFields / acf

Advanced Custom Fields
http://advancedcustomfields.com/
823 stars 168 forks source link

True/False field fold together and can't be changed/updated #900

Closed jccbbb closed 3 months ago

jccbbb commented 4 months ago

Describe the bug When using the True/False field in a field group and then checking it on a page for example does it immediately fold together and then it isn't possible to fold it out anymore to change/update the value.

To Reproduce Steps to reproduce the behavior:

  1. Create a field group with a True/False field.
  2. Set it to only show on Pages (as an example)
  3. Go to the field and check it.

Expected behavior It shouldn't fold together and the checkbox should be checked and possible to uncheck it afterwards as well.

Screenshots or Video acf field bug

Code `add_action( 'acf/include_fields', function() { if ( ! function_exists( 'acf_add_local_field_group' ) ) { return; }

acf_add_local_field_group( array(
'key' => 'group_65e5dd4b82fd6',
'title' => 'Disable footer on current page',
'fields' => array(
    array(
        'key' => 'field_65e5dd61f0f44',
        'label' => 'Do you want to disable the footer on this page?',
        'name' => 'disable_footer_on_this_page',
        'aria-label' => '',
        'type' => 'true_false',
        'instructions' => '',
        'required' => 0,
        'conditional_logic' => array(
            array(
                array(
                    'operator' => '',
                    'value' => '',
                ),
            ),
        ),
        'wrapper' => array(
            'width' => '',
            'class' => '',
            'id' => '',
        ),
        'wpml_cf_preferences' => 1,
        'message' => '',
        'default_value' => 0,
        'ui' => 0,
        'ui_on_text' => '',
        'ui_off_text' => '',
    ),
),
'location' => array(
    array(
        array(
            'param' => 'post_type',
            'operator' => '==',
            'value' => 'post',
        ),
    ),
    array(
        array(
            'param' => 'post_type',
            'operator' => '==',
            'value' => 'page',
        ),
    ),
    array(
        array(
            'param' => 'post_type',
            'operator' => '==',
            'value' => 'produkt',
        ),
    ),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'seamless',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => true,
'description' => '',
'show_in_rest' => 0,
'acfml_field_group_mode' => 'translation',

) ); } ); `

Version Information:

mattgrshaw commented 3 months ago

Hi @jccbbb

Did this field ever have conditional logic enabled? It looks like it's currently set up with partial conditional logic rules. If you change the code to the following it should work as expected:

acf_add_local_field_group( array(
    'key' => 'group_65e5dd4b82fd6',
    'title' => 'Disable footer on current page',
    'fields' => array(
        array(
            'key' => 'field_65e5dd61f0f44',
            'label' => 'Do you want to disable the footer on this page?',
            'name' => 'disable_footer_on_this_page',
            'aria-label' => '',
            'type' => 'true_false',
            'instructions' => '',
            'required' => 0,
            'conditional_logic' => 0,
            'wrapper' => array(
                'width' => '',
                'class' => '',
                'id' => '',
            ),
            'wpml_cf_preferences' => 1,
            'message' => '',
            'default_value' => 0,
            'ui' => 0,
            'ui_on_text' => '',
            'ui_off_text' => '',
        ),
    ),
    'location' => array(
        array(
            array(
                'param' => 'post_type',
                'operator' => '==',
                'value' => 'post',
            ),
        ),
        array(
            array(
                'param' => 'post_type',
                'operator' => '==',
                'value' => 'page',
            ),
        ),
        array(
            array(
                'param' => 'post_type',
                'operator' => '==',
                'value' => 'produkt',
            ),
        ),
    ),
    'menu_order' => 0,
    'position' => 'normal',
    'style' => 'seamless',
    'label_placement' => 'top',
    'instruction_placement' => 'label',
    'hide_on_screen' => '',
    'active' => true,
    'description' => '',
    'show_in_rest' => 0,
    'acfml_field_group_mode' => 'translation',
) );
} );

The only change there is switching conditional_logic from that array to 0, which is what ACF should export automatically if conditional logic has been disabled prior to export.

jccbbb commented 3 months ago

Hello @mattgrshaw,

Thank you for helping me! This has made me crazy a dozen of times haha 😄 Just one idea/question.

Wouldn't it be better than if you set it as active but then doesn't set any value in "Show this field if" at all that it would highlight an error on save? Or is there any use cases where someone would like to set "Conditional Logic to "True" but no value at all in "Show this field if"?

image
jccbbb commented 2 months ago

@mattgrshaw can you please get back to this with a reply of my last message? 😊