Support Forum
Support › Meta Box Conditional Logic › Problem with conditional logic used in a clonable group fieldResolved
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
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.
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.
That's really unfortunate!
Is there any way around this problem / a plan for a fix?
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.
Awesome! It is working with the latest update (1.15.7 - 2022-03-17)