BUG - Group creates a new group entry upon edit & save (MB Blocks extension)

Support MB Group BUG - Group creates a new group entry upon edit & save (MB Blocks extension)Resolved

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #46723
    ambrdigitalambrdigital
    Participant

    Hey there!

    We’ve come across a bug when using the Group extension with the MB Blocks extension.

    Whenever we save or edit any field within a block, the group field creates an extra entry, even if we didn’t intend to. This happens whether it's a single group or a nested group, and it always adds a clone in the first position of all the groups with the block.

    This issue is affecting all our sites using the Group extension with MB Blocks, and it's becoming a bit of a headache. We'd really appreciate a quick fix for this.

    For reference, we’re on the latest versions:

    Meta Box Version 5.10.2
    Meta Box AIO Version 1.30.2

    Hope this helps! Let us know if you need any more details. 🙂

    #46734
    BoatKungBoatKung
    Participant

    I just wanted to confirm that I’m experiencing the same issue.

    #46738
    PeterPeter
    Moderator

    Hello Ambr,

    Please export the field group to a JSON file and share it here with a screen record that illustrates the issue. I will check this on my demo site. You can follow the documentation to export the field group.
    https://docs.metabox.io/extensions/meta-box-builder/#export--import

    #46739
    SHANDASHANDA
    Participant

    I am having this issue with the tabs on this page https://opqic.org/omno/. Please share if you find a solution. I am seeing this issue on multiple client sites now.

    #46741
    ambrdigitalambrdigital
    Participant

    Hi Peter,

    We coded the block, I have added below the code of a test block that you can use to troubleshoot and test this bug, We reverted our Meta Box AIO plugin version to 1.30.0 and we do not get have the bug in this version. I suspect the bug is related to the plugin update with 1.30.1 - 2024-09-07 Fix issue with clone_empty_start, that woudl probably be a great place to start the investigation.

    Appreciate you looking in to this, let me how if you need any thing else.

    Cheers,
    Anthony

    meta-boxes__test-block.php

    <div><?php
    add_filter( 'rwmb_meta_boxes', 'test_block_meta_boxes' );
    function test_block_meta_boxes( $meta_boxes ) {
      $meta_boxes[] = [
        'title'           => 'Test Block',
        'id'              => "test-block",
        'type'            => 'block',
        'fields' => [
          [
            'type' => 'heading',
            'name' => 'Test Block',
          ],
          [
            'id' => "block_group",
            'type' => 'group',
            'clone' => true,
            'max_clone' => 3,
            'sort_clone' => true,
            'collapsible' => true,
            'save_state' => true,
            'group_title' => 'Group {#}',
            'add_button' => '+ Add Group',
            'fields' => [
              [
                'name' => 'Header',  
                'id'   => "block_header",
                'type' => 'textarea',
                'rows' => 1
              ],
              [
                'id' => "block_group_inner",
                'type' => 'group',
                'clone' => true,
                'sort_clone' => true,
                'collapsible' => true,
                'save_state' => true,
                'group_title' => 'Column {#}',
                'add_button' => '+ Add Test',
                'fields' => [
                  [
                    'name' => 'Inner Header',  
                    'id'   => "block_inner_header",
                    'type' => 'textarea',
                    'rows' => 1
                  ]
                ]
              ],
            ],
          ],
        ],  
      ];
      return $meta_boxes;
    };</div>

    block.json

    <div>{
      "$schema": "https://schemas.wp.org/trunk/block.json",
      "apiVersion": 3,
      "name": "meta-box/test-block",
      "title": "Test Block",
      "description": "The Test Block is a custom block that allows you to test the block editor.",
      "category": "common",
      "icon": "fas fa-truck-monster",
      "keywords": [
        "test",
        "block",
        "test block"
      ],
      "supports": {
        "anchor":true
      },
      "attributes": {
        "anchor":{
          "type": "string"
        },
        "g-block_group": {
          "type": "array"
        }
      },
      "render": "file:./test-block.php"
    }</div>

    .

    text-block.php

    <div><?php
    /**
     * @var array<string, mixed>[] $attributes The block attributes.
     * @var string $content The block default content.
     * @var \WP_Block $block The block instance.
     */
    
    $blockName = "test_block";
    $prefix = "block_";
    $class = "mb-block_" . $blockName;
    $id = ( $blockName . '-' . $attributes['id'] ?? '' );
    if ( ! empty( $attributes['anchor'] ) ) {
    	$id = $attributes['anchor'];
    }
    
    if( is_admin() || (defined( 'REST_REQUEST' ) && REST_REQUEST && 'edit' === $_GET['context'])) {
    	echo '<p>Test Block</p>';
    }
    
    $group = $attributes["{$prefix}group"] ?? null;
    if( !empty($group)){ 
    	var_dump($group);
    	foreach ( $group as $group_value ) {  
    		$header = isset( $group_value["{$prefix}header"] ) ? $group_value["{$prefix}header"] : null;
    		$group_inner = isset( $group_value["{$prefix}group_inner"] ) ? $group_value["{$prefix}group_inner"] : null;
    		?>
    		<div id="<?php echo $id; ?>" class="<?php echo $class ?> bg--blue">
    		<div class="container-fluid--small">
    			<div class="row">
    				<div class="col-12">
    					<?php if($header): ?>
    						<h2><?php echo $header; ?></h2>
    					<?php endif; ?>
    					<?php if( !empty($group_inner)){ 
    						foreach ( $group_inner as $group_value ) {  	
    							$inner_header = isset( $group_value["{$prefix}inner_header"] ) ? $group_value["{$prefix}inner_header"] : null;
    							?>
    							<div class="col-12">
    								<p><?php echo $inner_header; ?></p>
    							</div>
    						<?php } ?>
    					<?php } ?>
    				</div>
    			</div>
    		</div>
    	</div>
    <?php }
    }</div>
    #46742
    ambrdigitalambrdigital
    Participant

    Hi Peter, minor correct in the block.json file.

    <div>{
      "$schema": "https://schemas.wp.org/trunk/block.json",
      "apiVersion": 3,
      "name": "meta-box/test-block",
      "title": "Test Block",
      "description": "The Test Block is a custom block that allows you to test the block editor.",
      "category": "common",
      "icon": "fas fa-truck-monster",
      "keywords": [
        "test",
        "block",
        "test block"
      ],
      "supports": {
        "anchor":true
      },
      "attributes": {
        "anchor":{
          "type": "string"
        },
        "block_group": {
          "type": "array"
        }
      },
      "render": "file:./test-block.php"
    }</div>
    #46743
    PeterPeter
    Moderator

    Hello,

    Thanks for sharing, I can see the issue on the demo site. This has been escalated to the development team and we will work on this to fix the issue as soon as possible.

    #46776
    SHANDASHANDA
    Participant

    Checking on the status of this bug fix?

    #46898
    PeterPeter
    Moderator

    FYI, the fix for this issue is included in the new version of Meta Box AIO 1.30.5.

    #46917
    ambrdigitalambrdigital
    Participant

    Thank you

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.