Conditional logic + clonable group
Support › MB Conditional Logic › Conditional logic + clonable group
- This topic has 12 replies, 5 voices, and was last updated 8 years, 1 month ago by
grafik.
-
AuthorPosts
-
January 14, 2017 at 9:46 PM #4796
Jackky
ParticipantI'm making clonable groups with conditional radio buttons into each group, but conditional logic worked only in first group. I think it because unique id. So how to solve it?
add_filter( 'rwmb_meta_boxes', 'front_page_settings' ); function front_page_settings( $meta_boxes ) { $meta_boxes[] = array( 'id' => 'front_page_settings', 'title' => 'Настройки главной страницы', 'post_types' => array( 'page' ), 'context' => 'normal', 'priority' => 'high', 'include' => array( 'relation' => 'OR', 'ID' => get_option( 'page_on_front' ), ), 'fields' => array( array( 'name' => 'Категории, которые отображать на главной', 'id' => 'front_cats', 'type' => 'group', 'clone' => true, 'sort_clone' => true, 'fields' => array( array( 'id' => 'front_cat_type', 'name' => 'Тип категории', 'type' => 'radio', 'options' => array( 'animator' => 'Аниматоры', 'service' => 'Услуги', 'costume' => 'Костюмы' ), ), array( 'name' => 'Категория для отображения', 'id' => 'front_cat', 'type' => 'taxonomy_advanced', 'taxonomy' => 'animators', 'field_type' => 'select', 'hidden' => array( 'front_cat_type', '!=', 'animator' ) ), array( 'name' => 'Категория для отображения', 'id' => 'front_cat', 'type' => 'taxonomy_advanced', 'taxonomy' => 'servicies', 'field_type' => 'select', 'hidden' => array( 'front_cat_type', '!=', 'service' ) ), array( 'name' => 'Категория для отображения', 'id' => 'front_cat', 'type' => 'taxonomy_advanced', 'taxonomy' => 'costumes', 'field_type' => 'select', 'hidden' => array( 'front_cat_type', '!=', 'costume' ) ), array( 'name' => 'Заголовок перед категорией', 'id' => 'front_cat_title', 'type' => 'text' ), ), ), ), ); return $meta_boxes; }
January 14, 2017 at 11:21 PM #4797Jackky
ParticipantFind out some interesting thing:
If we change condition to
'hidden' => array( 'front_cats[1][front_cat_type]', '!=', 'animator' )
it will work for second clone only. So I just need to put something like php marker like front_cats[%s][front_cat_type] to make condition unique. How to do this?January 14, 2017 at 11:57 PM #4798Jackky
ParticipantWhen I changed 'field_type' to 'radio_list', it starts working, but only after I clone group, then save the page, and then I able to change condition in each created clone. But radio_list style is bad, I want to make it select or select_advanced.
January 15, 2017 at 8:47 AM #4801Anh Tran
KeymasterHi Jackky, I see you have several fields with the same ID
front_cat
. That breaks the functionality of the plugin, even it’s toggled by the Conditional Logic. You need to change the field IDs to make sure each field has an unique ID. Then the condition will work.January 15, 2017 at 1:23 PM #4803Jackky
ParticipantOk, thats worked better, but I don't like, that returned value in array had different second key, maybe there is a way to make id unique, but key equal? Also there still a small problem: when I clone the group, condition in the new clone doesn't work until I save the post (looks like it isn't in DOM).
January 15, 2017 at 3:33 PM #4804Jackky
ParticipantOh, I have just figured out, that taxanomy option, could be an array
'taxonomy' => array('animators','servicies','costumes'),
That solves my task in different way. Mark here https://metabox.io/docs/define-fields/#section-taxonomy that taxonomy could be an array or string.
And take your look at the problem with js above. Think it's important.January 16, 2017 at 6:20 PM #4817Anh Tran
KeymasterThank you Jackky! I will update the docs and check the JS issue.
January 17, 2017 at 8:17 PM #4830weseo
ParticipantHello, same Problem here, how you change the ids in $meta_boxes field definition?
January 19, 2017 at 9:29 AM #4844Anh Tran
KeymasterHi weseo,
You just need to change this:
array( 'name' => 'Категория для отображения', 'id' => 'CHANGE_THIS_TO_SOMETHING_ELSE', 'type' => 'taxonomy_advanced', 'taxonomy' => 'costumes', 'field_type' => 'select', 'hidden' => array( 'front_cat_type', '!=', 'costume' ) ),
March 30, 2017 at 8:48 AM #5435grafik
ParticipantI'm having the same problem, here is my code belo. The plugin seems to change ID's when a repeater is added, how do I get around this?
$meta_boxes[] = array( 'id' => 'post_images', 'title' => 'Post Images', 'pages' => array( 'post'), 'fields' => array( array( 'id' => 'post_image', 'type' => 'group', 'clone' => true, 'max_clone' => 15, 'sort_clone' => true, 'collapsible' => true, 'group_title' => 'image', 'fields' => array( array( 'name' => __( 'Layout', 'rwmb' ), 'id' => "{$prefix}image_layout_post", 'type' => 'select', 'options' => array( 'full' => __( 'Full Width Image', 'rwmb' ), 'double' => __( 'Double Image', 'rwmb' ), 'half' => __( 'Half Page Image', 'rwmb' ), ), 'multiple' => false, 'placeholder' => __( 'Select', 'rwmb' ), ), array( 'type' => 'heading', 'name' => 'Full Page Image', 'hidden' => array( 'meta_image_layout_post', '!=', 'full' ) ), array( 'name' => __( 'Image', 'rwmb' ), 'id' => "{$prefix}post_image_teaser_full", 'type' => 'image_advanced', 'max_file_uploads' => 1, 'clone' => false, 'hidden' => array( 'meta_image_layout_post', '!=', 'full' ) ), array( 'type' => 'heading', 'name' => 'Double Image', 'hidden' => array( 'meta_image_layout_post', '!=', 'double' ) ), array( 'name' => __( 'Image Left', 'rwmb' ), 'id' => "{$prefix}post_image_teaser_double", 'type' => 'image_advanced', 'max_file_uploads' => 1, 'clone' => false, 'hidden' => array( 'meta_image_layout_post', '!=', 'double' ) ), array( 'name' => __( 'Image Right', 'rwmb' ), 'id' => "{$prefix}post_image_teaser_double_two", 'type' => 'image_advanced', 'max_file_uploads' => 1, 'clone' => false, 'hidden' => array( 'meta_image_layout_post', '!=', 'double' ) ), array( 'type' => 'heading', 'name' => 'Image Options', 'hidden' => array( 'meta_image_layout_post', '!=', 'double' ) ), array( 'name' => __( 'Size', 'rwmb' ), 'id' => "{$prefix}image_arrangement", 'type' => 'select', 'options' => array( 'leftbig' => __( 'Left Image Bigger', 'rwmb' ), 'rightbig' => __( 'Right Image Bigger', 'rwmb' ), 'equal' => __( 'Images Equal Sizes', 'rwmb' ), ), 'multiple' => false, 'placeholder' => __( 'Select', 'rwmb' ), 'hidden' => array( 'meta_image_layout_post', '!=', 'double' ) ), array( 'type' => 'heading', 'name' => 'Half Page Image', 'hidden' => array( 'meta_image_layout_post', '!=', 'half' ) ), array( 'name' => __( 'Image', 'rwmb' ), 'id' => "{$prefix}post_image_teaser_half", 'type' => 'image_advanced', 'max_file_uploads' => 1, 'clone' => false, 'hidden' => array( 'meta_image_layout_post', '!=', 'half' ) ), array( 'name' => __( 'Align image', 'rwmb' ), 'id' => "{$prefix}half_image_align", 'type' => 'select', 'options' => array( 'left' => __( 'Align left', 'rwmb' ), 'center' => __( 'Align center', 'rwmb' ), 'right' => __( 'Align Right', 'rwmb' ), ), 'multiple' => false, 'placeholder' => __( 'Align ', 'rwmb' ), 'hidden' => array( 'meta_image_layout_post', '!=', 'half' ) ), ), ), ) );
March 31, 2017 at 4:28 AM #5439grafik
Participant*Bump* Any ideas? Is this bug or limitation?
April 4, 2017 at 4:23 AM #5472Tan Nguyen
ParticipantDear Grafik,
Sorry for long silence, I've tested your code and it works properly. Did you upgraded Conditional Logic to the latest version (1.4.1)?
Also, I see you set:
'id' => "{$prefix}image_layout_post",
But
'hidden' => array( 'meta_image_layout_post', '!=', 'full' )
Can you please make sure the
$prefix
variable ismeta_
?Cheers!
April 4, 2017 at 4:51 AM #5473grafik
ParticipantHi Tan, yip the prefix is meta_, I just upgraded from 1.4 to 1.4.1 and that seems to fix the issue, thanks for the response.
-
AuthorPosts
- The topic ‘Conditional logic + clonable group’ is closed to new replies.