Custom Fields
Re-Envisioned
Support Meta Box Conditional Logic Conditional logic not working with clones in groups Reply To: Conditional logic not working with clones in groups

#8484

npp
Participant

Yes I understand what you’re saying. But I have tried, and it is the same result. Try this code:


$prefix = '_something_';

$meta_boxes[] = array(
    'title'      => 'Box settings',
    'post_types' => 'page',
    'fields'     => array(
        array(
            'id'          	=> $prefix . 'test',
            'name'        	=> 'Image or video boxes',
            'type'        	=> 'group',
            'clone'       	=> true,
            'sort_clone'  	=> true,
            'collapsible' 	=> true,
            'default_state'	=> 'collapsed',
            'group_title' 	=> 'Box #{#}',
            'save_state' 	=> true,

            'fields' 		=> array(
				array(
				    'name'    			=> 'Image or video?',
				    'id'      			=> $prefix . 'type123',
				    'type'    			=> 'radio',
				    'options' 			=> [ 'img' => 'Image', 'vid' => 'Video', ],
				    'std'				=> 'img',
				    'inline' 			=> false,
				),
				array(
				    'id'               	=> $prefix . 'image',
				    'name'             	=> 'Choose an image',
				    'type'             	=> 'image_advanced',
				    'force_delete'     	=> false,
				    'max_file_uploads' 	=> 1,
				    'max_status'       	=> false,
				    'image_size'       	=> 'thumbnail',
				    'visible' 			=> [ $prefix . 'type', 'img' ], // <-- not working
				),
				array(
				    'id'               	=> $prefix . 'video',
				    'name'             	=> 'Choose video',
				    'type'             	=> 'video',
				    'force_delete'     	=> false,
				    'max_file_uploads' 	=> 1,
				    'max_status'       	=> false,
				    'visible' 			=> [ $prefix . 'type', 'vid' ], // <-- not working
				),
            ),
        ),
    ),
);

That should work, but it doesn’t. The reason I didn’t have a $prefix in there was because it’s a cloned group, it should *know* better. _something_test[0][type] isn’t post_type. But okay, if we don’t want to add logic to handle that, at least it should work with prefixed fields. But it doesn’t.

Problem 1 “sort of” disappears, the ‘default_state’ doesn’t work and one of the two alternatives are visible on page load until you expand. Then it disappears. Then if you select “Image”, set an image, and “clone”, the setting is lost (see problem #2).

Don’t know what to do. I’ll show you what happens here:
https://drive.google.com/file/d/18lzVdnsD8FrKVUlYgJzDNcF1v4lUSVB7/view?usp=sharing