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

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

Closed
slaFFik opened this issue Sep 8, 2016 · 4 comments
Closed

Comments

@slaFFik
Copy link
Member

slaFFik commented Sep 8, 2016

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)
    ) );
}
@tw2113
Copy link
Contributor

tw2113 commented Sep 8, 2016

@slaFFik can you reproduce with SCRIPT_DEBUG set to true? That'll use the unminified version of CMB2's js.

Related, as I was trying to recreate, I did run into these issues below with the console:

TypeError: $table.find(...).data(...) is undefined cmb2.js:120:46
cmb.resetTitlesAndIterator/</< /js/cmb2.js:120:46
.each /wp-includes/js/jquery/jquery.js:2:2879
n.prototype.each /wp-includes/js/jquery/jquery.js:2:844
cmb.resetTitlesAndIterator/< /js/cmb2.js:115:4
.each /wp-includes/js/jquery/jquery.js:2:2879
n.prototype.each /wp-includes/js/jquery/jquery.js:2:844
cmb.resetTitlesAndIterator /js/cmb2.js:112:3
n.event.dispatch /wp-includes/js/jquery/jquery.js:3:12392
n.event.add/r.handle /wp-includes/js/jquery/jquery.js:3:9156
n.event.trigger /wp-includes/js/jquery/jquery.js:3:11571
jQuery.event.trigger /wp-includes/js/jquery/jquery-migrate.js:633:9
.trigger/< /wp-includes/js/jquery/jquery.js:3:18983
.each /wp-includes/js/jquery/jquery.js:2:2879
n.prototype.each /wp-includes/js/jquery/jquery.js:2:844
.trigger /wp-includes/js/jquery/jquery.js:3:18962
cmb.removeAjaxRow /js/cmb2.js:606:4
n.event.dispatch /wp-includes/js/jquery/jquery.js:3:12392
n.event.add/r.handle /wp-includes/js/jquery/jquery.js:3:9156

@slaFFik
Copy link
Member Author

slaFFik commented Sep 8, 2016

Here is with SCRIPT_DEBUG:

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

@jtsternberg
Copy link
Member

Thank you for your awesomely detailed bug report. It should be fixed in trunk, but please re-open if not.

@tw2113
Copy link
Contributor

tw2113 commented Sep 8, 2016

As a followup, both of our errors originated from the same line, but we received different errors :D

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

3 participants