reaktivstudios / cmb2-flexible-content

A flexible content field for CMB2
14 stars 2 forks source link

'Remove group' creates an infinite number of groups #15

Open kevinr90 opened 6 years ago

kevinr90 commented 6 years ago

This plugin is working great for me - until I attempt to remove a group.

When doing this, the browser window freezes up and usually crashes completely.

When it doesn't crash, instead of removing my single group, it has actually created an uncountable number of groups.

I sometimes get the following message in console

Uncaught RangeError: Maximum call stack size exceeded
    at Cb (load-scripts.php:4)
    at a.fn.init.addClass (load-scripts.php:4)
    at HTMLButtonElement.cmb_flexible.addFlexibleRow (cmb2-flexible.js:82)
    at HTMLDivElement.dispatch (load-scripts.php:3)
    at HTMLDivElement.r.handle (load-scripts.php:3)
    at Object.trigger (load-scripts.php:3)
    at Object.a.event.trigger (load-scripts.php:9)
    at HTMLButtonElement.<anonymous> (load-scripts.php:3)
    at Function.each (load-scripts.php:2)
    at a.fn.init.each (load-scripts.php:2)

Removing non-flexible groups works perfectly.

My php code is

function bakehouse_cmb2_flexible_content() {
  $prefix = '_bh_';
  $cmb2_box_content = new_cmb2_box( array(
    'id'            => $prefix . 'flexible_content',
    'title'         => __( 'Page content', 'your-text-domain' ),
    'object_types' => array( 'page' ), // post type
    'context'       => 'normal',
    'priority'      => 'high',
    'show_names'    => true,
  ) );
  $cmb2_box_content->add_field(
    array(
      'name'       => __( 'Flexible content', 'cmb2-flexible' ),
      'id'         => $prefix . 'flexible',
      'type'       => 'flexible',
      'layouts' => array(
        // Text
        'text' => array(
          'title' => 'Text',
          'fields' => array(
            array(
              'name'    => 'Text',
              'id'      => $prefix . 'text',
              'type'    => 'text',
            ),
          )
        ),
        // End text
      )
    ) //End layouts

  );
}
add_action( 'cmb2_init', 'bakehouse_cmb2_flexible_content' );

infinite fields and error

reynoldspaul commented 5 years ago

This happens to me when it's the only group item. If there are more than 1 groups, 'remove' works until the last one.

Linssen21 commented 3 years ago

Hello any update on this I'm also facing the same problem