MB Conditional Logic is not working in Customizer

Support MB Settings Page MB Conditional Logic is not working in Customizer

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #32102
    RazibRazib
    Participant

    Conditional Logic is not working on Customize
    https://pastebin.com/embed_iframe/4rpW8buS?theme=dark

    #32113
    Long NguyenLong Nguyen
    Moderator

    Hi,

    The conditional logic works as well on my site, screen record https://share.getcloudapp.com/xQujoZyN

    You can try to deactivate all plugins except Meta Box, MB extensions and switch to the standard theme of WordPress to re-check this issue.

    #33660
    Gunther PilzGunther Pilz
    Participant

    Hi,

    I am having the same problem. The Conditional Logic is not working in Customizer.
    It works fine on the Settings Page but not if you use it in the Customizer.

    So there has to be definitely a bug - please check and correct.

    #33713
    Long NguyenLong Nguyen
    Moderator

    Hi Gunther,

    Can you please share the code that creates the fields and conditional logic on your site? As you can see on the screen record above, it works as well on my demo site.
    https://imgur.com/G4lFxi1

    #38836
    Ioannis TsimpidisIoannis Tsimpidis
    Participant

    Is this also true for when using conditional logic for fields inside a cloneable group in customizer?
    Currently this isn't working for me. Can you confirm?

    #38846
    Long NguyenLong Nguyen
    Moderator

    Hi Ioannis,

    Can you please share the code that creates the custom fields and conditional logic on your site? I will help you to check the issue.

    You can also follow this documentation to know how to use conditional logic with subfields in a group https://docs.metabox.io/extensions/meta-box-conditional-logic/#using-with-group

    #40257
    LucaLuca
    Participant

    Hi,
    I am having the same problem.

    The Conditional Logic is working in the Settings page, but it is not working in the Customizer.

    Please, see the video:
    https://share.getcloudapp.com/P8uNX1Lk

    With a clean WordPress installation (6.1.1),
    Meta Box 5.6.15,
    Meta Box AIO 1.17.0

    No other plugins
    No other Custom Fields
    No other Settings Pages
    All available extensions activated
    No console errors

    Custom Fields created with MB Builder:

    
    <?php
    add_filter( 'rwmb_meta_boxes', 'your_prefix_function_name' );
    
    function your_prefix_function_name( $meta_boxes ) {
        $prefix = '';
    
        $meta_boxes[] = [
            'title'          => __( 'Test 1', 'your-text-domain' ),
            'id'             => 'test-1',
            'settings_pages' => ['test'],
            'fields'         => [
                [
                    'name'    => __( 'Select', 'your-text-domain' ),
                    'id'      => $prefix . 'select_test_1',
                    'type'    => 'select',
                    'options' => [__( 'Hide{/translate}', '{translate}Show', 'your-text-domain' )],
                ],
                [
                    'name'    => __( 'Text', 'your-text-domain' ),
                    'id'      => $prefix . 'text_nhbsf837xqg',
                    'type'    => 'text',
                    'visible' => [
                        'when'     => [['select_test_1', '=', 1]],
                        'relation' => 'or',
                    ],
                ],
            ],
        ];
    
        return $meta_boxes;
    }
    

    Thanks in advance

    #40264
    PeterPeter
    Moderator

    Hello Luca,

    The options of the select field look incorrect when setting up. Please change it to this one and let me know if it works.

    'fields'         => [
        [
            'name'    => __( 'Select', 'your-text-domain' ),
            'id'      => $prefix . 'select_test_1',
            'type'    => 'select',
            'options' => [
                'a' => __( 'A', 'your-text-domain' ),
                'b' => __( 'B', 'your-text-domain' ),
                'c' => __( 'C', 'your-text-domain' ),
    
            ],
        ],
        [
            'name'    => __( 'Text', 'your-text-domain' ),
            'id'      => $prefix . 'text_nhbsf837xqg',
            'type'    => 'text',
            'visible' => [
                'when'     => [['select_test_1', '=', 'b']],
                'relation' => 'or',
            ],
        ],
    ]
    #40267
    LucaLuca
    Participant

    Hi Peter,
    thanks for answer me.

    The code reported in my previous post was provided from the "Get PHP Code" of the Builder (Choices= 0:Hide
    1:Show) and I agree it looks a bit messy

    I have tried with your modifications and still obtains same results (working nicely in settings page and not working in Customizer):

    https://share.getcloudapp.com/QwujBKkG

    I also noticed that by trying the Customizer repeatedly, sometimes it works correctly. But I have not found a consistent behavior.

    I have used the following:

    Clean WordPress installation (6.1.1),
    Meta Box 5.6.15,
    Meta Box AIO 1.17.0

    Theme: Twenty Twenty-Two

    No other plugins
    No Custom Fields via Builder
    No Settings Pages via Builder
    All MB available extensions activated
    No console errors

    Settings Page and Custom Fields created with the following code in functions.php:

    
    add_filter( 'mb_settings_pages', 'lm_settings_page' );
    function lm_settings_page( $settings_pages ) {
    	$settings_pages[] = [
            'menu_title' => __( 'LM: Test', 'your-text-domain' ),
            'id'         => 'lm-settings-test',
            'position'   => 25,
            'style'      => 'boxes',
            'columns'    => 1,
            'customizer' => true,
            'icon_url'   => 'dashicons-admin-generic',
        ];
    
    	return $settings_pages;
    }
    
    add_filter( 'rwmb_meta_boxes', 'lm_meta_boxes' );
    function lm_meta_boxes( $meta_boxes ) {
        $prefix = '';
    
        $meta_boxes[] = [
            'title'          => __( 'LM: Test 1', 'your-text-domain' ),
            'id'             => 'test-2',
            'settings_pages' => ['lm-settings-test'],
    
    		'fields'         => [
    			[
    				'name'    => __( 'Select', 'your-text-domain' ),
    				'id'      => $prefix . 'select_test_1',
    				'type'    => 'select',
    				'options' => [
    					'a' => __( 'A', 'your-text-domain' ),
    					'b' => __( 'B', 'your-text-domain' ),
    					'c' => __( 'C', 'your-text-domain' ),
    
    				],
    			],
    			[
    				'name'    => __( 'Text', 'your-text-domain' ),
    				'id'      => $prefix . 'text_nhbsf837xqg',
    				'type'    => 'text',
    				'visible' => [
    					'when'     => [['select_test_1', '=', 'b']],
    					'relation' => 'or',
    				],
    			],
    		]
    
        ];
    
        return $meta_boxes;
    }
    
    

    I am glad to help investigate this problem.
    Please, let me know.

    #40272
    PeterPeter
    Moderator

    Hello,

    I don't see that issue on my end, here is the screen record https://monosnap.com/file/M2QPFXucFX9PAVkRRg87QvVcIqeB9Y

    If the conditional logic still does not work in the customizer on your site, please share your site credentials to the contact form https://metabox.io/contact/
    I will help you to check the issue.

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.