Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wysiwyg editor in group causes JS error #1031

Closed
mclaurent opened this issue Oct 4, 2017 · 8 comments
Closed

wysiwyg editor in group causes JS error #1031

mclaurent opened this issue Oct 4, 2017 · 8 comments

Comments

@mclaurent
Copy link

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',
    ));

}```
@tw2113
Copy link
Contributor

tw2113 commented Oct 5, 2017

One thing I want to point out is that WYSIWYG field types are denoted as not available as repeatable fields, as shown at https://github.com/CMB2/CMB2/wiki/Field-Types. Likely for reasons like this.

@jtsternberg
Copy link
Member

@tw2113 wysiwyg field types will not work with the repeatable flag, but they should work fine in a repeatable group.

@jtsternberg
Copy link
Member

@mclblock are you trying to use on a post-type that does not have editor in the supports array? It's possible that is the cause of the problem.

@tw2113
Copy link
Contributor

tw2113 commented Oct 5, 2017

Noted on the clarification, thanks Justin

@mclaurent
Copy link
Author

mclaurent commented Oct 6, 2017

Thanks @tw2113 and @jtsternberg for the information. Just confirming that I am using wysiwyg in a repeatable group and that I'm not using the repeatable flag. It looks like the "Disable the visual editor when writing" option (WP-Admin > Users > Your Profile) was enabled which in turn caused an error in the tinyMCE initialisation. I've re-enabled the visual editor and this has brought back the WYSIWYG in the repeatable group.
Is there a way to avoid the JS error so that other scripts can execute correctly?

@jtsternberg
Copy link
Member

I'm still not able to replicate the issue. Can you test after disabling other plugins?

@jtsternberg
Copy link
Member

jtsternberg commented Oct 6, 2017

I lied (it helps when you "save" after you toggle the Disable the visual editor setting). Pushing up a fix shortly.

@Scorpio256
Copy link

Hi I have same error. To replicate it all you need to do is move block more than once.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants