Tet banner

Custom Fields
Support Meta Box Conditional Logic Strange behaviour of conditional fields within cloneable group

  • Creator
  • #18207

    I have a repeatable group of image & oembed field. I'd like to show the video field when there's no image set and hide otherwise.
    Initially, this works for the first group (instance). When I add the image within the first group and click "Add item" button, the second set has the other fields hidden but image, although I didn't add any image there. What is more, when I do nothing but click "Add item" third time, I have again two empty fields working properly. And so on - every fields group after the group with image works bad and every group after the group without image works well.

    I hope you'll be able to re-create this strange behaviour and address the issue.

    The code:

    $meta_boxes[] = array(
            'id'         => 'gallery',
            'title'      => esc_html__( 'Gallery', 'myplugin-meta-box' ),
            'post_types' => array( 'page' ),
            'context'    => 'normal',
            'priority'   => 'high',
            'autosave'   => false,
            'fields'     => array(
                    'name'       => esc_html__( 'Gallery items', 'myplugin-meta-box' ),
                    'id'         => $prefix . 'gallery',
                    'type'       => 'group',
                    'clone'      => true,
                    'sort_clone' => true,
                    'add_button' => '+ ' . esc_html__( 'Add item', 'myplugin-meta-box' ),
                    'fields'     => array(
                            'id'     => 'image-id',
                            'type'   => 'single_image',
                            'name'   => esc_html__( 'Image', 'myplugin-meta-box' ),
                            'type'   => 'custom_html',
                            'std'    => esc_html__( 'or embed a video:', 'myplugin-meta-box' ),
                            'visible' => array( 'image-id', 0 ),
                            'id'     => 'video-url',
                            'name'   => esc_html__( 'Video', 'myplugin-meta-box' ),
                            'type'   => 'oembed',
                            'size'   => 39,
                            'visible' => array( 'image-id', 0 ),
  • You must be logged in to reply to this topic.