wpmetabox / meta-box

The best plugin for WordPress custom fields and custom meta boxes
https://metabox.io
1.19k stars 422 forks source link

Meta Box Group: Removing parent group - when having nested groups - don't remove minus(-) button on first group #1045

Open kairos-xx opened 7 years ago

kairos-xx commented 7 years ago
function toggleRemoveButtons( $container )
{
        var $button = $container.find( '.remove-clone' );
    $button.toggle( $button.length > 1 );
}

Possible solution:

function toggleRemoveButtons( $container )
{
        var $button = $container.find( '.remove-clone' );
        var parentButton = $button.parentsUntil( '.rwmb-input' );
        var countGroup = parentButton.parent().find( '.rwmb-clone' );
    for (var i = 0; i < countGroup.length; i++) 
        {
        var counter = $(countGroup[i]).siblings($( '.rwmb-clone' )).length;
        if(counter == 1)
        {
            $(countGroup[i]).children( '.remove-clone' ).hide();
        }
        else 
        {
            $(countGroup[i]).children( '.remove-clone' ).show();
        }
    }
}
Pascalmh commented 7 years ago

I thought I had the same Issue but I think this is how it is supposed to work - "works as designed". There needs to be an initial Group as it is the one thats the one that is cloneable. If you want to delete the initial group, you need to remove its contents (or add a new group, then delete the first one and then save the page/post).