Skip to content

wysiwyg editor in group causes JS error #1031

@mclaurent

Description

@mclaurent

Expected Behavior:

When a WYSIWYG editor is embedded in a repeatable-group field, it should just repeat and be available to the editor

Actual Behavior:

The editor displays as a textarea and does not initialise sa a WYSIWYG editor. In the console, the following error appears:

cmb2-wysiwyg.js?ver=2.2.5.3:284 Uncaught TypeError: Cannot read property 'init' of undefined
    at Object.wysiwyg.init (cmb2-wysiwyg.js?ver=2.2.5.3:284)
    at HTMLTextAreaElement.<anonymous> (cmb2-wysiwyg.js?ver=2.2.5.3:144)
    at Function.each (jquery.js?ver=1.12.4:2)
    at jQuery.fn.init.each (jquery.js?ver=1.12.4:2)
    at HTMLDocument.wysiwyg.initAll (cmb2-wysiwyg.js?ver=2.2.5.3:134)
    at HTMLDocument.dispatch (jquery.js?ver=1.12.4:3)
    at HTMLDocument.r.handle (jquery.js?ver=1.12.4:3)
    at Object.trigger (jquery.js?ver=1.12.4:3)
    at Object.jQuery.event.trigger (jquery-migrate.js?ver=1.4.1:633)
    at HTMLDocument.<anonymous> (jquery.js?ver=1.12.4:3)

I am using CMB2 as a PHP include and I'm on version 2.2.5.3

Steps to reproduce:

  1. Create a new Metabox
    2.Add a repeatable group to all pages
  2. Add a WYSIWYG editor into the group.
  3. Go onto a page and look at the meta box
  4. observe the WYSIWYG not initialising.

CMB2 Field Registration Code:

namespace com\company\wordpress;


add_action('cmb2_admin_init', 'com\company\wordpress\custom_meta_box');
function custom_meta_box()
{
    $prefix = 'wp_custom_metabox';

    $cmb = new_cmb2_box(array(
        'id' => $prefix . 'metabox',
        'title' => esc_html__('CMB2 WYSIWYG issue', 'cmb2'),
        'object_types' => array('page'), // Post type
        'context' => 'normal',
        'priority' => 'high',
        'show_names' => true, // Show field names on the left
    ));

    $cmb_group = $cmb->add_field(array(
        'id' => $prefix . 'group',
        'type' => 'group',
        'description' => __('Generates reusable form entries', 'cmb2'),
        // 'repeatable'  => false, // use false if you want non-repeatable group
        'options' => array(
            'group_title' => __('Entry {#}', 'cmb2'), // since version 1.1.4, {#} gets replaced by row number
            'add_button' => __('Add Another Entry', 'cmb2'),
            'remove_button' => __('Remove Entry', 'cmb2'),
            'sortable' => true, // beta
        ),
    ));

    $cmb->add_group_field($cmb_group, array(
        'name' => esc_html__('Title', 'cmb2'),
        'id' => 'title',
        'type' => 'wysiwyg',
    ));

}```

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