Conditional Logic Between Checklist Group and Checkbox

Support MB Conditional Logic Conditional Logic Between Checklist Group and Checkbox

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1391
    JustinJustin
    Participant

    I have a checklist group that is set to be hidden when another checkbox (not in the checklist group) is not checked. This conditional logic works only if no checkboxes in the checklist group are checked. If even one checkbox in the checklist group is checked, the conditional logic breaks.

    #1419
    Tan NguyenTan Nguyen
    Participant

    Hi Justin, sorry for long silence, I'm checking this issue and give you an answer shortly 🙂

    #1420
    Tan NguyenTan Nguyen
    Participant

    Dear Justin,

    I've checked with and it works, can you please tell me what's version you're using and provide your code to register meta boxes and define conditional logic?

    Here's my snippet for example:

    
    add_filter( 'rwmb_meta_boxes', function( $meta_boxes )
    {
    	$meta_boxes[] = array(
    		'id' => 'brand_product',
    		'title' => 'Brands and Products',
    		'post_types' => array( 'post', 'page' ),
    		'context'	=> 'normal',
    		'priority'	=> 'high',
    		'fields' => array(
    			array(
    				'id' => 'show_checkboxlist',
    				'name' => 'Show Checkbox List',
    				'desc' => 'Show Checkbox List when this checkbox is checked',
    				'type' => 'checkbox'
    			),
    			array(
    				'id'	=> 'brand',
    				'name'	=> 'Brand',
    				'desc'	=> 'Pick Your Favourite Brand',
    				'type'	=> 'checkbox_list',
    				'options' => array(
    					'Apple' 		=> 'Apple',
    					'Google' 		=> 'Google',
    					'Microsoft' 	=> 'Microsoft'
    				),
    				'visible' => array('show_checkboxlist', true)
    			)
    		)
    	);
    
    	return $meta_boxes;
    } );
    

    Best regards

    Tan

    #1424
    JustinJustin
    Participant

    Meta Box: 4.5.6
    Conditional Logic: 1.0.7

    Code:

    
    // Projects
    	$prefix = 'projects_';
    	$projects_divisions = get_terms( 'projects_division', array( 'hide_empty' => 0 ) );
    	$projects_categories = get_terms( 'projects_category', array( 'hide_empty' => 0 ) );
    	$projects_categories_list = array();
    	$projects_division_cats_options = array();
    	
    	// Get and store categories
    	foreach ($projects_categories as $category) {
    		$projects_categories_list[$category->slug] = $category->name;
    	}
    	
    	// Create divisions and categories options
    	foreach ($projects_divisions as $division) {
    		$name = $division->name;
    		$slug = $division->slug;
    		
    		$projects_division_cats_options[] = array(
    		   'name' => __( '', $prefix ),
    			'id' => $prefix . $slug,
    			'type' => 'checkbox_list', // List used instead of single (preferred styling)
    			'options' => array(
    				1 => __( $name, $prefix ),
    			)
    		);
    		
    		$projects_division_cats_options[] = array(
    		   'name' => __( '<div style="width:7px; margin-top:-4px; border-right:1px solid #aaa;">&nbsp;</div>', $prefix ),
    			'id' => $prefix . $slug . '_categories',
    			'type' => 'checkbox_list',
    			'options' => $projects_categories_list,
    			'hidden' => array($prefix . $slug, 0),
    			'after' => '<div style="border-top:1px solid #ededed; height:7px;" />&nbsp;</div>',
    		);
    	}
    	
    	// Divisions and Categories
        $meta_boxes[] = array(
    		'id' => $prefix.'divisions_categories',
            'title' => 'Divisions & Categories',
            'pages' => array( 'projects' ),
    		'context' => 'side',
            'priority' => 'low',
            'fields' => $projects_division_cats_options,
        );
    #1438
    Tan NguyenTan Nguyen
    Participant

    Hi Justin,

    Thanks again for contacting us, I've checked your registered code and see that's a bug and we'll list in in our documentation shortly.

    That bug happen when you define two field with similar ID, for example, 'hello' and 'hello_foo' or 'hello*' (* matches any characters)

    To workaround, you can update:

    
    'id' => $prefix . $slug . '_categories',
    

    To

    
    'id' => $prefix . 'categories_' . $slug,
    

    Best regards

    Tan Nguyen

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Conditional Logic Between Checklist Group and Checkbox’ is closed to new replies.