Block complex field conditional logic does not work
Version
- Carbon Fields: 3.1.20
- WordPress: 5.5.1
- PHP: 7.4.3
Expected Behavior
I expect the internal_item field to display when target_type is set to Internal and external_url field to display when target_type is set to External.
Actual Behavior
Both the internal_item and external_url fields display regardless of the target_type value
Steps to Reproduce the Problem
- Add code attached below
- Add block to post or page via post edit screen
- Toggle the values of the
Target Typefield
Comments
Block::make( __( 'Hero', 'td') )
->add_fields( array(
Field::make( 'complex', 'hero_items', __( 'Items', 'td' ) )
->add_fields( array(
Field::make( 'image', 'image', __( 'Image', 'td' ) )
->set_help_text( __( '1600px by 900px minimum', 'td' ) ),
Field::make( 'text', 'heading', __( 'Heading', 'td' ) ),
Field::make( 'rich_text', 'text', __( 'Text', 'td' ) ),
Field::make( 'radio', 'target_type', __( 'Target Type' ) )
->add_options( array(
0 => __( 'Internal', 'td' ),
1 => __( 'External', 'td' ),
) ),
Field::make( 'association', 'internal_item', __( 'Internal Item', 'td' ) )
->set_max( 1 )
->set_conditional_logic( array(
array(
'field' => 'target_type',
'value' => 0,
),
) )
->set_types( array(
array(
'type' => 'post',
'post_type' => 'post'
),
array(
'type' => 'post',
'post_type' => 'page'
),
) ),
Field::make( 'text', 'external_url', __( 'External URL', 'td' ) )
->set_conditional_logic( array(
array(
'field' => 'target_type',
'value' => 1,
),
) ),
) )
) )
->set_render_callback( array( __CLASS__, 'render_block_hero' ) );

Is there any update on this?
Duplicate of #800 but no update on it at the moment
This has been fixed in development - ff6ac7808f17c04e4255cc267bb2185290db5800 -- and will be available in the next release :-)
@jorostoyanov
The fix doesn't work for conditional logic inside complex fields. I just tested it. It works fine otherwise but the behaviour described by @clubdeuce above is still the same for complex fields.
The issue should be re-opened.
I have the same issue
Hi @clubdeuce, @ChipRyan and @ProjetKotov
We've fixed the conditional logic inside of a block with a complex field in our latest release v3.5.2.