meta-box
meta-box copied to clipboard
Meta Box Group: Removing parent group - when having nested groups - don't remove minus(-) button on first group
- having "n" cloned groups (
PARENT:.rwmb-clone), with "n" cloned sub-groups (CHILD:.rwmb-clone) - when I remove the second
PARENT - the first
PARENTkeep the :.remove-clone button.
That's because in clone.js function toggleRemoveButtons ( $container ):
- the toggle visibility is defined by
$button.length > 1. - Since there are some
.remove-clone buttoninCHILD - This condition doesn't apply
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();
}
}
}
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).