meta-box icon indicating copy to clipboard operation
meta-box copied to clipboard

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

Open kairos-xx opened this issue 9 years ago • 1 comments

  • having "n" cloned groups (PARENT: .rwmb-clone), with "n" cloned sub-groups (CHILD: .rwmb-clone)
  • when I remove the second PARENT
  • the first PARENT keep 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 button in CHILD
  • 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();
		}
	}
}

kairos-xx avatar Jan 06 '17 09:01 kairos-xx

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).

Pascalmh avatar Oct 17 '17 08:10 Pascalmh