Conditional logic + clonable group

Support MB Conditional Logic Conditional logic + clonable group

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #4796
    JackkyJackky
    Participant

    I'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;
    }
    
    #4797
    JackkyJackky
    Participant

    Find 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?

    #4798
    JackkyJackky
    Participant

    When 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.

    #4801
    Anh TranAnh Tran
    Keymaster

    Hi 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.

    #4803
    JackkyJackky
    Participant

    Ok, 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).

    #4804
    JackkyJackky
    Participant

    Oh, 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.

    #4817
    Anh TranAnh Tran
    Keymaster

    Thank you Jackky! I will update the docs and check the JS issue.

    #4830
    weseoweseo
    Participant

    Hello, same Problem here, how you change the ids in $meta_boxes field definition?

    #4844
    Anh TranAnh Tran
    Keymaster

    Hi 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' )
    ),
    #5435
    grafikgrafik
    Participant

    I'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' )
    
    				),
    			
    
    			),
    		),
    
    	)
    );
    
    #5439
    grafikgrafik
    Participant

    *Bump* Any ideas? Is this bug or limitation?

    #5472
    Tan NguyenTan Nguyen
    Participant

    Dear 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 is meta_?

    Cheers!

    #5473
    grafikgrafik
    Participant

    Hi 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.

Viewing 13 posts - 1 through 13 (of 13 total)
  • The topic ‘Conditional logic + clonable group’ is closed to new replies.