Skip to content

Commit

Permalink
Ability to have groups closed by default. Closes #391
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsternberg committed Jul 15, 2015
1 parent 9b9fe95 commit 9d691b1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.

* Updated/Added many translations. Props [fxbenard](https://github.com/fxbenard), ([#203](https://github.com/WebDevStudios/CMB2/pull/344)) and [Mte90](https://github.com/Mte90) for the Italian translation.
* Updated `file_list` to have a more intutive selection in the media library, and updated the 'Use file' text in the button. Props [SteveHoneyNZ](https://github.com/SteveHoneyNZ) ([#357](https://github.com/WebDevStudios/CMB2/pull/357), [#358](https://github.com/WebDevStudios/CMB2/pull/358)).
* `'closed'` group field option parameter introduced in order to set the groups as collapsed by default. Requested in [#391](https://github.com/WebDevStudios/CMB2/issues/391).

### Bug Fixes

Expand Down
1 change: 1 addition & 0 deletions example-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ function yourprefix_register_repeatable_group_field_metabox() {
'add_button' => __( 'Add Another Entry', 'cmb2' ),
'remove_button' => __( 'Remove Entry', 'cmb2' ),
'sortable' => true, // beta
// 'closed' => true, // true to have the groups closed by default
),
) );

Expand Down
3 changes: 2 additions & 1 deletion includes/CMB2.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,10 @@ public function render_group( $args ) {
public function render_group_row( $field_group, $remove_disabled ) {

$field_group->peform_param_callback( 'before_group_row' );
$closed_class = $field_group->options( 'closed' ) ? ' closed' : '';

echo '
<div class="postbox cmb-row cmb-repeatable-grouping" data-iterator="', $field_group->index, '">';
<div class="postbox cmb-row cmb-repeatable-grouping', $closed_class, '" data-iterator="', $field_group->index, '">';

if ( $field_group->args( 'repeatable' ) ) {
echo '<button ', $remove_disabled, 'data-selector="', $field_group->id(), '_repeat" class="dashicons-before dashicons-no-alt cmb-remove-group-row"></button>';
Expand Down
4 changes: 3 additions & 1 deletion tests/test-cmb-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,8 @@ public function test_group_field_param_callbacks() {
$cmb = cmb2_get_metabox( 'test2' );

$field_id = $cmb->update_field_property( 'group_field', 'before_group', 'before_group output' );
$field_id = $cmb->update_field_property( 'group_field', 'options', array( 'closed' => true ) );

$this->assertTrue( ! empty( $field_id ) );

$cmb->update_field_property( 'group_field', 'before_group_row', 'before_group_row output' );
Expand All @@ -455,7 +457,7 @@ public function test_group_field_param_callbacks() {
</div>
</div>
before_group_row output
<div class="postbox cmb-row cmb-repeatable-grouping" data-iterator="0">
<div class="postbox cmb-row cmb-repeatable-grouping closed" data-iterator="0">
<button disabled="disabled" data-selector="group_field_repeat" class="dashicons-before dashicons-no-alt cmb-remove-group-row"></button>
<div class="cmbhandle" title="Click to toggle"><br></div>
<h3 class="cmb-group-title cmbhandle-title"><span></span></h3>
Expand Down

0 comments on commit 9d691b1

Please sign in to comment.