Switch field inside the group - Content visibility & required condition
- This topic has 5 replies, 3 voices, and was last updated 3 weeks, 6 days ago by
Tan Nguyen.
-
AuthorPosts
-
October 27, 2022 at 10:48 AM #38843
Prabakaran Shankar
ParticipantHello,
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; }
October 27, 2022 at 3:25 PM #38851Long Nguyen
ModeratorHi,
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
October 27, 2022 at 5:48 PM #38856Prabakaran Shankar
ParticipantHi,
I did not expressed the query correctly. Could you please take a look at the video?
https://1drv.ms/v/s!AjLgaRuebK87hp0ATrnu5DrX0A1v8w?e=Cednf8In the subgroup, the "required" condition in the field blocks the save post process in the hidden state.
October 27, 2022 at 10:51 PM #38861Long Nguyen
ModeratorHi,
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.
October 28, 2022 at 9:39 AM #38866Prabakaran Shankar
ParticipantThank you for your consideration to fix it.
March 20, 2025 at 11:11 AM #47868Tan Nguyen
ParticipantDear Prabakaran,
We have fixed since v1.6.21. If you use conditional logic above that version, this issue should be resolved. Cheers!
-
AuthorPosts
- You must be logged in to reply to this topic.