Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block complex field conditional logic does not work #923

Closed
clubdeuce opened this issue Oct 14, 2020 · 6 comments
Closed

Block complex field conditional logic does not work #923

clubdeuce opened this issue Oct 14, 2020 · 6 comments

Comments

@clubdeuce
Copy link

clubdeuce commented Oct 14, 2020

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
Copy link
Author

Is there any update on this?

@ChipRyan
Copy link

ChipRyan commented Nov 3, 2020

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

@jorostoyanov
Copy link
Contributor

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

@ChipRyan
Copy link

ChipRyan commented Nov 7, 2020

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

@jorostoyanov jorostoyanov reopened this Nov 9, 2020
@ProjetKotov
Copy link

I have the same issue

@HTMLBurger-NG
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants