Skip to content

Live previews don't work for oEmbed fields within a repeatable group #1157

Closed

Description

@johnbillion

Expected Behavior:

When an oembed field type is present within a repeatable group, it should function as normal.

Actual Behavior:

The live Ajax-powered embed preview does not function, because the call to cmb2_ajax() never triggers, and thus its Ajax handlers are never registered. Ref:

CMB2/includes/CMB2.php

Lines 1444 to 1449 in 393388b

case 'oembed':
// Initiate oembed Ajax hooks.
cmb2_ajax();
break;

Steps to reproduce (I have confirmed I can reproduce this issue on the trunk branch):

  1. Register a repeatable group and place an oembed field type in it.
  2. Paste an embed URL into the oEmbed URL input field.
  3. Observe that the live preview doesn't function. The Ajax call responds with 0 because there's no registered Ajax handler for the oEmbed preview.

CMB2 Field Registration Code:

add_action( 'cmb2_init', function() {
	// Meta box
	$cmb_main_box = new_cmb2_box( [
		'id'           => 'main_box',
		'title'        => 'Main Content',
		'object_types' => [
			'post',
		],
	] );

	// Repeatable embed group
	$cmb_embed_group = $cmb_main_box->add_field( [
		'id'         => 'embeds',
		'repeatable' => true,
		'type'       => 'group',
	] );

	// Repeatable field: embed
	$cmb_main_box->add_group_field( $cmb_embed_group, [
		'id'      => 'url',
		'name'    => 'Embed URL',
		'type'    => 'oembed',
	] );
} );

Activity

  1. changed the title [-]Previews don't work for oEmbed fields within a repeatable group[/-] [+]Live previews don't work for oEmbed fields within a repeatable group[/+] on Aug 1, 2018
  2. Fiorinol commented on Sep 2, 2019

    @Fiorinol

    I'm having this issue as well and I've noticed nobody commented on it in more than a year. Is there a way to register an ajax handler for this?

  3. added a commit that references this issue on Sep 3, 2019
    7cb3e00
  4. added a commit that references this issue on Apr 28, 2020
    a9bb103
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions