carbon-fields icon indicating copy to clipboard operation
carbon-fields copied to clipboard

Block complex field conditional logic does not work

Open clubdeuce opened this issue 5 years ago • 5 comments

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

  1. Add code attached below
  2. Add block to post or page via post edit screen
  3. Toggle the values of the Target Type field

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' ) );

Screen Shot 2020-10-14 at 12 03 12 PM

clubdeuce avatar Oct 14 '20 16:10 clubdeuce

Is there any update on this?

clubdeuce avatar Oct 29 '20 16:10 clubdeuce

Duplicate of #800 but no update on it at the moment

ChipRyan avatar Nov 03 '20 06:11 ChipRyan

This has been fixed in development - ff6ac7808f17c04e4255cc267bb2185290db5800 -- and will be available in the next release :-)

jorostoyanov avatar Nov 04 '20 12:11 jorostoyanov

@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.

ChipRyan avatar Nov 07 '20 11:11 ChipRyan

I have the same issue

ProjetKotov avatar May 18 '21 09:05 ProjetKotov

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.

HTMLBurger-NG avatar Mar 08 '23 13:03 HTMLBurger-NG