Support Forum
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;
}
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
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.
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.
Thank you for your consideration to fix it.