Problem with conditional logic used in a clonable group field

Support MB Conditional Logic Problem with conditional logic used in a clonable group fieldResolved

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #33622
    mikew@clientengagementacademy.com[email protected]
    Participant

    Hello,

    I am having an issue with conditional logic used in a clonable group field. The logic does not apply to clones, it only applies to the default group.

    Here is the code I am using:

    <?php
    add_filter( 'rwmb_meta_boxes', 'your_prefix_function_name' );
    
    function your_prefix_function_name( $meta_boxes ) {
        $prefix = '';
    
        $meta_boxes[] = [
            'id'         => 105,
            'post_types' => ['part'],
            'fields'     => [
                [
                    'name'          => __( 'Group', 'your-text-domain' ),
                    'id'            => $prefix . 'group_hlso8r8au9',
                    'type'          => 'group',
                    'clone'         => true,
                    'clone_default' => true,
                    'fields'        => [
                        [
                            'name'    => __( 'Select', 'your-text-domain' ),
                            'id'      => $prefix . 'select_e8av28xu5t4',
                            'type'    => 'select',
                            'options' => [
                                'yes' => __( 'Yes', 'your-text-domain' ),
                                'no'  => __( 'No', 'your-text-domain' ),
                            ],
                            'std'     => 'no',
                        ],
                        [
                            'name'    => __( 'Text', 'your-text-domain' ),
                            'id'      => $prefix . 'text_r1urjedt9w',
                            'type'    => 'text',
                            'visible' => [
                                'when'     => [['select_e8av28xu5t4', '=', 'yes']],
                                'relation' => 'or',
                            ],
                        ],
                    ],
                ],
            ],
        ];
    
        return $meta_boxes;
    }

    And the video:
    https://watch.screencastify.com/v/Bco0JG5Hfnq12nrCviXW

    Could you investigate the issue or instruct me on what I am doing wrong?

    Thank you in advance

    #33679
    Long NguyenLong Nguyen
    Moderator

    Hi Mike,

    The conditional logic works with the name of the input box. The subfield in a cloneable group will have the input name groupID[index][subfieldID], for example

    group_hlso8r8au9[0][select_e8av28xu5t4]
    group_hlso8r8au9[1][select_e8av28xu5t4]

    You need to put the input name exactly to make the conditional logic works.

    'visible' => [
        'when'     => [['group_hlso8r8au9[0][select_e8av28xu5t4]', '=', 'yes']],
        'relation' => 'or',
    ],

    But it will apply to all cloneable groups, so in general, it is not recommended to use the conditional logic with a cloneable field or group.

    #33740
    mikew@clientengagementacademy.com[email protected]
    Participant

    Thank you for the reply. Unfortunately, being able to use conditional logic in a cloneable group is crucial in my project, so for now I will be switching to an alternative to Meta Box solution. If you happen to include this functionality in future releases please let me know.

    #34262
    uptwouptwo
    Participant

    That's really unfortunate!
    Is there any way around this problem / a plan for a fix?

    #34461
    alpha.mediaalpha.media
    Participant

    Is there no way to re-attach whatever javascript listeners there are whenever a new clone group is created? I would think there is a codeable solution to this.

    I could have sworn this feature used to work before as I have received bug reports from clients with cloned fields no longer working with conditional fields.

    #34577
    uptwouptwo
    Participant

    Awesome! It is working with the latest update (1.15.7 - 2022-03-17)

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