Switch field inside the group - Content visibility & required condition

Support General Switch field inside the group - Content visibility & required conditionResolved

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #38843
    Prabakaran ShankarPrabakaran Shankar
    Participant

    Hello,
    Switch or radio field inside the group to set a condition to show or hide the other fields with required condition does not work properly. However, the same is works properly when its outside the group.

    <?php
    add_filter( 'rwmb_meta_boxes', 'your_prefix_function_name' );
    
    function your_prefix_function_name( $meta_boxes ) {
        $prefix = '';
    
        $meta_boxes[] = [
            'title'      => __( 'User Profile 2', 'your-text-domain' ),
            'id'         => 'user-profile-2',
            'post_types' => ['user-profile'],        
            'fields'     => [
                [
                    'name'  => __( 'Switch', 'your-text-domain' ),
                    'id'    => $prefix . 'switch_rho0wrvojnh',
                    'type'  => 'switch',
                    'style' => 'rounded',
                ],
                [
                    'id'      => $prefix . 'usp_details_2',
                    'type'    => 'group',
                    'fields'  => [
                        [
                            'type' => 'heading',
                            'name' => __( 'Teaching Experience', 'your-text-domain' ),
                        ],
                        [
                            'name'    => __( 'Radio', 'your-text-domain' ),
                            'id'      => $prefix . 'radio_erjktwzg16',
                            'type'    => 'radio',
                            'options' => [
                                'show' => __( 'show', 'your-text-domain' ),
                                'hide' => __( 'hide', 'your-text-domain' ),
                            ],
                            'inline'  => false,
                        ],
                        [
                            'name'      => __( 'Teaching Experience Details', 'your-text-domain' ),
                            'id'        => $prefix . 'tea_vis',
                            'type'      => 'switch',
                            'on_label'  => 'Hide',
                            'off_label' => 'Show or Add',
                            'std'       => true,
                        ],
                        [
                            'name'       => __( 'Teaching experience details', 'your-text-domain' ),
                            'id'         => $prefix . 'teaexp',
                            'type'       => 'wysiwyg',
                            'raw'        => true,
                            'options'    => [
                                'media_buttons' => false,
                            ],
                            'required'   => true,
                            'attributes' => [
                                'maxlength' => 2000,
                                'minlength' => 100,
                                'required'  => true,
                            ],
                            // this condition not  working with 'required'
                            'visible'    => [
                                'when'     => [['tea_vis', '=', 1], ['radio_erjktwzg16', '=', 'show']],
                                'relation' => 'or',
                            ],
                        ],
                    ],
                    // this condition working with 'required'
                    'visible' => [
                        'when'     => [['switch_rho0wrvojnh', '=', 1]],
                        'relation' => 'or',
                    ],
                ],
            ],
        ];
    
        return $meta_boxes;
    }
    
    #38851
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Please 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

    #38856
    Prabakaran ShankarPrabakaran Shankar
    Participant

    Hi,
    I did not expressed the query correctly. Could you please take a look at the video?
    https://1drv.ms/v/s!AjLgaRuebK87hp0ATrnu5DrX0A1v8w?e=Cednf8

    In the subgroup, the "required" condition in the field blocks the save post process in the hidden state.

    #38861
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Thanks for your additional information.

    The nested logic in this case is not working correctly. I've escalated this to the development team to fix it in the next update.

    #38866
    Prabakaran ShankarPrabakaran Shankar
    Participant

    Thank you for your consideration to fix it.

    #47868
    Tan NguyenTan Nguyen
    Participant

    Dear Prabakaran,

    We have fixed since v1.6.21. If you use conditional logic above that version, this issue should be resolved. Cheers!

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