Skip to content

Conversation

@jtsternberg
Copy link
Member

Description

Fixes issues with repeatable and sortable group with repeatable fields while shifting group. Fixes #1426

Testing procedure

  1. Add a bunch of field types (preferably all of them?) to the a group field.

    1. Make sure some of them are set to be repeatable.
    2. e.g.:
    add_action( 'cmb2_admin_init', function() {
    
    	$cmb = new_cmb2_box([
    		'id'            => 'metabox_attachment',
    		'title'         => 'Poo poo',
    		'object_types'  => [ 'page' ], // Post type
    		'priority'      => 'high',
    		'show_names'    => true
    	] );
    
    	$group_field_id = $cmb->add_field( array(
    		'before_group' => function( $args, $field ) {
    			echo '<xmp>'. __LINE__ .') $field->value: '. print_r( $field->value, true ) .'</xmp>';
    		},
    		'id'          => 'wiki_test_repeat_group_1429',
    		'type'        => 'group',
    		'description' => __( 'Generates reusable form entries', 'cmb2' ),
    		'repeatable'  => true,
    		'options'     => array(
    			'group_title'   => __( 'Entry {#}', 'cmb2' ),
    			'add_button'    => __( 'Add Another Entry', 'cmb2' ),
    			'remove_button' => __( 'Remove Entry', 'cmb2' ),
    			'sortable'      => true,
    		),
    	) );
    
    	$cmb->add_group_field( $group_field_id, array(
    			'name' => 'Entry Title',
    			'id'   => 'subtitle',
    			'type' => 'text',
    			'repeatable' => true,
    	) );
    
    	$cmb->add_group_field( $group_field_id, array(
    		'name'       => 'Test Image',
    		'desc'       => 'Upload an image or enter a URL.',
    		'id'         => 'demo_image',
    		'type'       => 'file',
    		'preview_size'    => array( 50, 50 ),
    	) );
    	$cmb->add_group_field( $group_field_id, array(
    		'name'         => 'Multiple Files',
    		'desc'         => 'Upload or add multiple images/attachments.',
    		'id'           => 'demo_file_list',
    		'type'         => 'file_list',
    	) );
    
    	$cmb->add_group_field( $group_field_id, array(
    		'name'    => 'Color',
    		'id'      => 'demo_color',
    		'type'    => 'colorpicker',
    		'default' => '#ffffff',
    	) );
    });
  2. In first group click to repeat field and populate both https://prnt.sc/13o8bn2

  3. Add another group ( Add another Entry )

  4. Click move down on first group.

  5. See that all works as expected.

  6. After moving fields around, try click/dragging repeatable field items

  7. Once tested for a bit, save the post.

  8. See that data is saved properly.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

@jtsternberg jtsternberg self-assigned this Jun 3, 2021
@jtsternberg
Copy link
Member Author

@DJMIMi I would really appreciate if you could test this.

@kelin1003
Copy link

@jtsternberg

I'm facing this same issue and can confirm that this PR fixes the issue and everything seems to be working fine. I've tested with multiple fields.

Any estimation on how long before this gets released?

@tw2113
Copy link
Contributor

tw2113 commented Jun 7, 2021

For what it's worth, I believe the develop branch is still pretty solid right now so if you're needing the fix ASAP, pulling a copy of Develop would be possible

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

Successfully merging this pull request may close these issues.

Repeatable and sortable group with repeatable fields, issue with group shift

4 participants