Problem with conditional logic used in a clonable group field
Support › MB Conditional Logic › Problem with conditional logic used in a clonable group fieldResolved
- This topic has 5 replies, 4 voices, and was last updated 3 years, 1 month ago by
uptwo.
-
AuthorPosts
-
February 2, 2022 at 8:29 PM #33622
[email protected]
ParticipantHello,
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/Bco0JG5Hfnq12nrCviXWCould you investigate the issue or instruct me on what I am doing wrong?
Thank you in advance
February 6, 2022 at 10:15 PM #33679Long Nguyen
ModeratorHi 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 examplegroup_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.
February 8, 2022 at 5:26 PM #33740[email protected]
ParticipantThank 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.
March 3, 2022 at 4:54 PM #34262uptwo
ParticipantThat's really unfortunate!
Is there any way around this problem / a plan for a fix?March 11, 2022 at 12:51 AM #34461alpha.media
ParticipantIs 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.
March 17, 2022 at 7:16 PM #34577uptwo
ParticipantAwesome! It is working with the latest update (1.15.7 - 2022-03-17)
-
AuthorPosts
- You must be logged in to reply to this topic.