Skip to content

Removing repeatable text field from a group should not produce js error #729

@slaFFik

Description

@slaFFik

Expected Behavior:

Removing newly added repeatable text field from a group should not produce js error.

Actual Behavior:

Here is the error that I receive:

Uncaught TypeError: Cannot read property 'replace' of undefined
.../app/plugins/cmb2/js/cmb2.min.js?ver=2.2.2.1 line 1

Steps to reproduce:

  1. Download the CMB2 plugin from WP repo
  2. Create a group field, with several field in it
  3. Make one of the text fields repeatable.
  4. On editing screen add a new field via clicking Add Row button under this field.
  5. Right after that click Remove button on any of that repeatable items
  6. Observe the browser console.

CMB2 Field Registration Code:

add_action( 'cmb2_admin_init', 'yourprefix_register_demo_metabox' );
function yourprefix_register_demo_metabox() {
    $prefix = 'kumbaya';

    $cmb = new_cmb2_box( array(
                         'id'           => 'test_metabox',
                         'title'        => __( 'Settings', 'cmb2' ),
                         'object_types' => array( 'my_post_type', ), // Post type
                         'context'      => 'normal',
                         'priority'     => 'high',
                         'show_names'   => true, // Show field names on the left
    ) );

    $group_field_id = $cmb->add_field( array(
                                   'id'          => 'wiki_test_repeat_group',
                                   'type'        => 'group',
                                   'description' => __( 'Set of Fields Settings', 'cmb2' ),
                                   'repeatable'  => false, // use false if you want non-repeatable group
                                   'options'     => array(
                                       'group_title'   => __( 'Group Name', 'cmb2' ), 
                                       'add_button'    => __( 'Add Another Entry', 'cmb2' ),
                                       'remove_button' => __( 'Remove Entry', 'cmb2' ),
                                       'sortable'      => true, // beta
                                   ),
    ) );

    // Title
    $cmb->add_group_field( $group_field_id, array(
        'name'        => __( 'Title', 'cmb2' ),
        'description' => __( 'field description (optional)', 'cmb2' ),
        'id'          => $prefix . '_title',
        'type'        => 'text',
        'attributes'  => [],
         'repeatable' => true, // Repeatable fields are supported w/in repeatable groups (for most types)
    ) );
}

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