Skip to content

Repeatable WYSIWYG breaks if quicktags false #796

@timburden

Description

@timburden

Expected Behavior:

WYSIWYG fields without quicktags should be repeatable too

Actual Behavior:

Adding new groups containing a WYSIWYG field which has quicktags => false in its options produces a javascript error.

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

  1. Go to the options page you have created.
  2. Add another group containing the WYSIWYG field with quicktags => false
  3. Observe JS error in console: "Uncaught TypeError: window.quicktags is not a function" in cmb2.min.js

CMB2 Field Registration Code:

    /**
     * Do the options fields with CMB2
     */
    function options_metaboxes() {

        // Hook in our save notices.
        add_action( "cmb2_save_options-page_fields_{$this->metabox_id}", array( $this, 'settings_notices' ), 10, 2 );

        $cmb = new_cmb2_box( array(
            'id'         => $this->metabox_id,
            'hookup'     => false,
            'cmb_styles' => false,
            'show_on'    => array(
            // These are important, don't remove.
            'key'   => 'options-page',
            'value' => array( $this->key ),
            ),
        ) );

        $cmb->add_field( array(
            'name' => 'Modules Directory',
            'description' => 'Relative to current theme directory. Defaults to sjm_content_modules',
            'id'   => 'alternate_directory',
            'type' => 'text',
            'default' => 'sjm_content_modules',
        ) );

        $module_placements = $cmb->add_field( array(
            'id'          => 'module_placements',
            'type'        => 'group',
            'description' => __( 'Module Placements', 'cmb' ),
            'repeatable' => true,
            'options'     => array(
                'group_title'   => __( 'Module Placement {#}', 'cmb' ),
                'add_button'    => __( 'Add Another Placement', 'cmb2' ),
                'remove_button' => __( 'Remove Placement', 'cmb2' ),
                'sortable'      => false,
                'closed'     => true,
            ),
            'after_group' => array( $this, 'change_group_titles' ),
        ) );

        $cmb->add_group_field( $module_placements, array(
            'name'             => __( 'Label', 'cmb2' ),
            'id'               => 'label',
            'type'             => 'text',
        ) );

        $cmb->add_group_field( $module_placements, array(
            'name' => 'Default Modules',
            'description' => 'Enter default modules for this placement here',
            'id'   => 'default_shortcodes',
            'type' => 'wysiwyg',
            'options' => array(
                'wpautop' => false,
                'media_buttons' => false,
                'tinymce' => array(
                    'toolbar1' => 'sjmcm_editor_button',
                    'toolbar2' => false,
                ),
                'quicktags' => false,
            ),
        ) );
    }

I have confirmed that the 'quicktags' => false is the line that breaks things. I am on the trunk branch.

I have a fix which I will put in a pull request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions