Carbon-fields: Conditional logic in Gutenberg block fields no longer working

Created on 11 Dec 2019  路  14Comments  路  Source: htmlburger/carbon-fields

Version

  • Carbon Fields: 3.1.8
  • WordPress: 5.3
  • PHP: 7.3

Expected Behavior

Show/hide fields based on other field(s) in the same Gutenberg Block

Actual Behavior

All fields show by default, the conditional logic has no effect

Container definition

Block::make( __( 'My Shiny Gutenberg Block' ) )
    ->add_fields( array(
        Field::make( 'select', 'crb_show_socials', 'Show Socials' )
            ->add_options( array(
                'yes' => 'Yes',
                'no' => 'No',
            ) ),

        Field::make( 'text', 'crb_facebook', 'Facebook URL' )
            ->set_conditional_logic( array(
                'relation' => 'AND',
                array(
                    'field' => 'crb_show_socials',
                    'value' => 'no',
                    'compare' => '=',
                )
            ) ),
    ) )
    ->set_render_callback( function ( $fields, $attributes, $inner_blocks ) {
        ?>

        <?php
    } );

Comments

Tested on a fresh WP install. Console errors/warnings screenshot below. I reckon it has something to do with Gutenberg v6 in WP 5.3.

image

Most helpful comment

@HeroBanana

Your solution seems to fix this issue.

I have committed it to the development branch - ff6ac7808f17c04e4255cc267bb2185290db5800

It will be available shortly in the new release!

All 14 comments

We have the same issue

Same issue for me, any news ?

Still an issue in version v3.1.11.

After some debugging I found out that the this line cause issues:
https://github.com/htmlburger/carbon-fields/blob/development/packages/core/hocs/with-conditional-logic/index.js#L55

The property effect for blocks contains an object of name -> value but for metaboxes it is the default one.

By using has function we can check the field:

// Possible fix for issue 800
// When function has has failed use find.
const fieldExists = has(effect, props.name) || find( effect, [ 'id', props.id ] );

Still an issue in v3.1.14

@jorostoyanov what is the status?

Any update on this?

still an issue in v3.1.20. Eagerly waiting on a fix for this.

Any update on this?

Conditional logic in Gutenberg block fields is not working at all, any update on it??

@HeroBanana

Your solution seems to fix this issue.

I have committed it to the development branch - ff6ac7808f17c04e4255cc267bb2185290db5800

It will be available shortly in the new release!

Hi @jorostoyanov , I reopen this isssue because conditional logic working :( I have this code :

$extend[] = Field::make('select', 'action_type', "Type d'action")
    ->set_options([
        'link_action' => "Lien personnalis茅",
        'custom_action' => "Action personnalis茅e"
    ]);
$extend[] = Field::make('select', 'action_name', 'Action')
    ->set_options([
        'hello' => 'Hello',
        'test' => 'Test',
        'votirue' => 'Voiture'
    ])
    ->set_conditional_logic([
        'relation' => 'AND', [
            'field' => 'action_type',
            'value' => 'custom_action',
            'compare' => '=',
        ]
    ]);
$extend[] = Field::make('text', 'button_label', "Nom du lien")
    ->set_conditional_logic([
        'relation' => 'AND', [
            'field' => 'action_type',
            'value' => 'custom_action',
            'compare' => '=',
        ]
    ]);
$extend[] = Field::make('text', 'button_link', "Lien")
    ->set_conditional_logic([
        'relation' => 'AND', [
            'field' => 'action_type',
            'value' => 'custom_action',
            'compare' => '=',
        ]
    ]);

The conditionnal logic work for action_name field, but not working for button_label and button_link fields.

Capture d鈥櫭ヽran du 2021-02-14 18-32-22

Capture d鈥櫭ヽran du 2021-02-14 18-31-53

I have a small error in the console :

Warning: WithEffects defines an invalid contextType. contextType should point to the Context object returned by React.createContext(). However, it is set to undefined. This can be caused by a typo or by mixing up named and default imports. This can also happen due to a circular dependency, so try moving the createContext() call to a separate file.
    in WithEffects
    in Unknown (created by WithSelect(WithEffects))
    in WithSelect(WithEffects) (created by WithConditionalLogic(WithDispatch(WithDispatch(WithEffects))))
    in WithConditionalLogic(WithDispatch(WithDispatch(WithEffects))) (created by WithFilters(WithFilters(SelectField)))
    in WithFilters(WithFilters(SelectField)) (created by BlockEdit)
    in div (created by Field)
    in div (created by Field)
    in Field
    in Unknown (created by WithFilters(Field))
    in WithFilters(Field)
    in Unknown (created by WithSelect(WithFilters(Field)))
    in WithSelect(WithFilters(Field)) (created by WithFilters(WithSelect(WithFilters(Field))))
    in WithFilters(WithSelect(WithFilters(Field))) (created by BlockEdit)
    in div (created by BlockEdit)
    in BlockEdit
    in Unknown (created by WithSelect(BlockEdit))
    in WithSelect(BlockEdit) (created by Edit)
    in Edit (created by WithToolbarControls(Edit))
    in WithToolbarControls(Edit) (created by WithInspectorControl(WithToolbarControls(Edit)))
    in WithInspectorControl(WithToolbarControls(Edit)) (created by WithInspectorControl(WithInspectorControl(WithToolbarControls(Edit))))
    in WithInspectorControl(WithInspectorControl(WithToolbarControls(Edit))) (created by WithToolbarControls(WithInspectorControl(WithInspectorControl(WithToolbarControls(Edit)))))
    in WithToolbarControls(WithInspectorControl(WithInspectorControl(WithToolbarControls(Edit))))
    in Unknown (created by WithDispatch(Component))
    in WithDispatch(Component)
    in Unknown (created by WithMultipleValidation(WithToolbarControls(WithInspectorControl(WithInspectorControl(WithToolbarControls(Edit))))))
    in WithMultipleValidation(WithToolbarControls(WithInspectorControl(WithInspectorControl(WithToolbarControls(Edit))))) (created by WithFilters(Edit))
    in WithFilters(Edit) (created by block_edit_BlockEdit)
    in block_edit_BlockEdit (created by block_BlockListBlock)
    in div (created by block_Block)
    in block_Block (created by block_BlockListBlock)
    in BlockCrashBoundary (created by block_BlockListBlock)
    in block_BlockListBlock (created by (block_BlockListBlock))
    in (block_BlockListBlock) (created by ((block_BlockListBlock)))
    in ((block_BlockListBlock)) (created by WithFontSizeInlineStyles(((block_BlockListBlock))))
    in WithFontSizeInlineStyles(((block_BlockListBlock)))
    in Unknown (created by WithSelect(WithFontSizeInlineStyles(((block_BlockListBlock)))))
    in WithSelect(WithFontSizeInlineStyles(((block_BlockListBlock)))) (created by WithDefaultAttributes(WithSelect(WithFontSizeInlineStyles(((block_BlockListBlock))))))
    in WithDefaultAttributes(WithSelect(WithFontSizeInlineStyles(((block_BlockListBlock))))) (created by WithFilters(block_BlockListBlock))
    in WithFilters(block_BlockListBlock) (created by IfCondition(WithFilters(block_BlockListBlock)))
    in IfCondition(WithFilters(block_BlockListBlock)) (created by WithDispatch(IfCondition(WithFilters(block_BlockListBlock))))
    in WithDispatch(IfCondition(WithFilters(block_BlockListBlock)))
    in Unknown (created by Pure(WithSelect(WithDispatch(IfCondition(WithFilters(block_BlockListBlock))))))
    in Pure(WithSelect(WithDispatch(IfCondition(WithFilters(block_BlockListBlock))))) (created by Items)
    in Items (created by BlockListItems)
    in BlockListItems (created by ForwardRef(BlockList))
    in div (created by ForwardRef(RootContainer))
    in div (created by InsertionPoint)
    in InsertionPoint (created by ForwardRef(RootContainer))
    in ForwardRef(RootContainer) (created by ForwardRef(BlockList))
    in ForwardRef(BlockList) (created by VisualEditor)
    in div (created by ObserveTyping)
    in ObserveTyping (created by WithSafeTimeout(ObserveTyping))
    in WithSafeTimeout(ObserveTyping) (created by VisualEditor)
    in div (created by WritingFlow)
    in div (created by WritingFlow)
    in WritingFlow (created by VisualEditor)
    in div (created by CopyHandler)
    in CopyHandler (created by VisualEditor)
    in div (created by Typewriter)
    in Typewriter
    in Unknown (created by WithSelect(Typewriter))
    in WithSelect(Typewriter) (created by VisualEditor)
    in div (created by BlockSelectionClearer)
    in BlockSelectionClearer (created by VisualEditor)
    in VisualEditor (created by Layout)
    in div (created by InterfaceSkeleton)
    in div (created by InterfaceSkeleton)
    in div (created by InterfaceSkeleton)
    in div (created by InterfaceSkeleton)
    in InterfaceSkeleton (created by NavigateRegions(InterfaceSkeleton))
    in div (created by NavigateRegions(InterfaceSkeleton))
    in NavigateRegions(InterfaceSkeleton) (created by Layout)
    in div (created by FocusReturnProvider)
    in FocusReturnProvider (created by Layout)
    in Layout (created by Editor)
    in ErrorBoundary (created by Editor)
    in BlockEditorProvider
    in Unknown (created by Context.Consumer)
    in WithRegistryProvider(BlockEditorProvider) (created by EditorProvider)
    in BlockContextProvider (created by EditorProvider)
    in EntityProvider (created by EditorProvider)
    in EntityProvider (created by EditorProvider)
    in EditorProvider (created by WithDispatch(EditorProvider))
    in WithDispatch(EditorProvider)
    in Unknown (created by WithSelect(WithDispatch(EditorProvider)))
    in WithSelect(WithDispatch(EditorProvider))
    in Unknown (created by Context.Consumer)
    in WithRegistryProvider(WithSelect(WithDispatch(EditorProvider))) (created by Editor)
    in div (created by DropZoneProvider)
    in DropZoneProvider (created by Editor)
    in slot_fill_provider_SlotFillProvider (created by SlotFillProvider)
    in SlotFillProvider (created by Editor)
    in StrictMode (created by Editor)
    in Editor (created by WithDispatch(Editor))
    in WithDispatch(Editor)
    in Unknown (created by WithSelect(WithDispatch(Editor)))
    in WithSelect(WithDispatch(Editor)) react-dom.js:82:32

Carbon field version : https://github.com/htmlburger/carbon-fields/releases/tag/v3.2.1
Wordpress: 5.6
PHP : 7.3

Same problem here, but I get no errors in the console. Works when using as a container for post_meta and theme_options but not a block:

image

Carbon Fields: 3.2.1
WordPress: 5.6.2
PHP: 7.3

The problem still exists (v3.4.0-beta.1). The logical conditions in Gutenberg don't work.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

olegburakov picture olegburakov  路  3Comments

halvardos picture halvardos  路  4Comments

jonwaldstein picture jonwaldstein  路  3Comments

AlexBa picture AlexBa  路  3Comments

jquimera picture jquimera  路  4Comments