Custom Fields
Re-Envisioned
Support Meta Box Group Is it possible to disable the ‘remove’ option of a clonable group?

  • Creator
    Topic
  • #19054
    Resolved Yard Digital
    Participant

    I have built a clonable group like the following example from the docs:
    https://docs.metabox.io/extensions/meta-box-group/#setting-default-group-values

    The std values are being dynamically filled (creating about 8 group clones). I want the user to be able to change the data of each group and to reorder these clones, but not to add or delete any cloned groups.

    I have been able to remove the ‘add more’ button by setting: 'max_clone' => 3.
    Is there a way to also get rid of the option to ‘remove’ clones?

    Or is there another way to achieve what I want with metabox?

    Example from the docs:

    
    add_filter( 'rwmb_meta_boxes', function( $meta_boxes ) {
        $meta_boxes[] = [
            'title' => 'Test Meta Box',
            'fields' => [
                [
                    'type' => 'group',
                    'id'   => 'group',
                    'name' => 'Group',
                    'clone' => true,
                    'collapsible' => true,
                    'group_title' => '{name}',
                    'fields' => [
                        [
                            'type' => 'text',
                            'id' => 'name',
                            'name' => 'Name',
                        ],
                        [
                            'type' => 'email',
                            'id' => 'email',
                            'name' => 'Email',
                        ],
                    ],
                    'std' => [
                        // Value for the 1st clone
                        [
                            'name' => 'Name 1',
                            'email' => 'email1@domain.com',
                        ],
    
                // Value for the 2nd clone
                [
                    'name' => 'Name 2',
                    'email' => 'email2@domain.com',
                ]
            ],
        ]
    ],
    
    ];
    return $meta_boxes;
    
    } );
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #19160
    Long Nguyen
    Moderator

    Hi there,

    Unfortunately, the plugin does not support to remove the option remove in the clone group but you can use the CSS code to hide this button easily. Add this code to the file functions.php in the theme folder or use Code Snippets plugin

    add_action( 'admin_footer', function() {
        ?>
        <style type="text/css">
            .rwmb-group-clone .rwmb-group-remove,
            .rwmb-group-clone .remove-clone {
                display: none !important;
            }
        </style>
        <?php
    } );

    Let me know how it goes.

    #20733
    Yard Digital
    Participant

    Hi,

    Thanks for you response. Removing the clone button with display none worked for me.

    Thanks!

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