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

Multiple entries of complex field containing radio field have unexpected behavior

Open clubdeuce opened this issue 5 years ago • 3 comments

Version

  • Carbon Fields: 3.1.20
  • WordPress: 5.5.1
  • PHP: 7.4.3

Expected Behavior

I expect to be able to set individual Target Type radio field options for each entry in the complex field group without affecting the other entries.

Actual Behavior

Selecting an option in one entry for the block will alter the instances of the target_type field in other entries.

Steps to Reproduce the Problem

  1. Add the block code attached below.
  2. Add one instance of this block to one post or page.
  3. Add multiple entries to the hero block.
  4. Set the target_type of the first entry to one of the available values, e.g. click on Internal and the button is now sahded blue.
  5. Go to the second entry and select an option for the target_type. The second entry's target_type option will now be shaded blue and the target_type option for entry one is now no longer shaded blue and it appears that the entry is cleared.

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

    }

clubdeuce avatar Oct 14 '20 16:10 clubdeuce

Hello, clubdeuce

We managed to reproduce the problem and started working on a fix.

Panchev avatar Oct 16 '20 11:10 Panchev

Thank you, @Panchev.

clubdeuce avatar Oct 16 '20 16:10 clubdeuce

update?

clubdeuce avatar Sep 01 '23 05:09 clubdeuce