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 type field error in Group field #54

Open
K15Lmk98 opened this issue Jan 10, 2018 · 0 comments
Open

Wysiwyg type field error in Group field #54

K15Lmk98 opened this issue Jan 10, 2018 · 0 comments

Comments

@K15Lmk98
Copy link

Sorry, this is an automatic translation.

Clean installation - WP 4.9.1 - Cmb2 2.3.0 - Twentysixteen

Hello,
Using a wysiwyg field, in Group field I receive a Javascript error in console:
"cmb2-conditionals.js?ver=1.0.4:220 Uncaught TypeError: Cannot read property 'replace' of undefined
at CMB2ConditionalsFindDependants (cmb2-conditionals.js?ver=1.0.4:220)"

The first instance of the group has no problems.

But if I create a new instance "Add Another Entry" the error appears.

To solve this problem I modified the file "cmb2-conditionals.js" on line 220.
From:
fieldName = fieldName.replace( /[]$/, '' );
TO:
if ( fieldName ) {
fieldName = fieldName.replace( /[]$/, '' );
}

Is it possible, when you have time, to update the plugin to avoid this error?

Code Cmb2
`/* Hook in and add a metabox to demonstrate repeatable grouped fields */
add_action( 'cmb2_admin_init', 'yourprefix_register_repeatable_group_field_metabox' );
function yourprefix_register_repeatable_group_field_metabox() {
$prefix = 'yourprefix_group_';

/**
 * Repeatable Field Groups
 */
$cmb_group = new_cmb2_box( array(
	'id'           => $prefix . 'metabox',
	'title'        => esc_html__( 'Repeating Field Group', 'cmb2' ),
	'object_types' => array( 'post', 'page' ),
) );

// $group_field_id is the field id string, so in this case: $prefix . 'demo'
$group_field_id = $cmb_group->add_field( array(
	'id'          => $prefix . 'demo',
	'type'        => 'group',
	'description' => esc_html__( 'Generates reusable form entries', 'cmb2' ),
	'options'     => array(
		'group_title'   => esc_html__( 'Entry {#}', 'cmb2' ), // {#} gets replaced by row number
		'add_button'    => esc_html__( 'Add Another Entry', 'cmb2' ),
		'remove_button' => esc_html__( 'Remove Entry', 'cmb2' ),
		'sortable'      => true, // beta
		// 'closed'     => true, // true to have the groups closed by default
	),
) );

/**
 * Group fields works the same, except ids only need
 * to be unique to the group. Prefix is not needed.
 *
 * The parent field's id needs to be passed as the first argument.
 */
$cmb_group->add_group_field( $group_field_id, array(
	'name'       => esc_html__( 'Entry Title', 'cmb2' ),
	'id'         => 'title',
	'type'       => 'text',
	// 'repeatable' => true, // Repeatable fields are supported w/in repeatable groups (for most types)
) );

$cmb_group->add_group_field( $group_field_id, array(
	'name'        => esc_html__( 'Description', 'cmb2' ),
	'description' => esc_html__( 'Write a short description for this entry', 'cmb2' ),
	'id'          => 'description',
	'type'        => 'textarea_small',
) );

$cmb_group->add_group_field( $group_field_id, array(
	'name'    => esc_html__( 'Test wysiwyg', 'cmb2' ),
	'desc'    => esc_html__( 'field description (optional)', 'cmb2' ),
	'id'      => $prefix . 'wysiwyg',
	'type'    => 'wysiwyg',
	'options' => array( 'teeny' => true, 'wpautop' => false, 'media_buttons' => false, 'textarea_rows' => 10 ),
) );

$cmb_group->add_group_field( $group_field_id, array(
	'name' => esc_html__( 'Entry Image', 'cmb2' ),
	'id'   => 'image',
	'type' => 'file',
) );

$cmb_group->add_group_field( $group_field_id, array(
	'name' => esc_html__( 'Image Caption', 'cmb2' ),
	'id'   => 'image_caption',
	'type' => 'text',
) );

}`

Thanks, Claudio_

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

1 participant