Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions classes.fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,10 @@ public function parse_save_values() {

$field_value = $field->get_values();

// if the field is a repeatable field, store the whole array of them, if it's not repeatble,
// just store the first (and only) one directly
if ( ! $field->args['repeatable'] )
$field_value = reset( $field_value );
}
}

Expand Down
23 changes: 15 additions & 8 deletions tests/testGroupField.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ class GroupFieldTestCase extends WP_UnitTestCase {
function testAddField() {

$group = new CMB_Group_Field( 'group', 'Group Title', array() );
$field1 = new CMB_Text_Field( 'foo', 'Title', array( 1, 2 ) );
$field2 = new CMB_Text_Field( 'bar', 'Title', array( 3, 4 ) );
$field1 = new CMB_Text_Field( 'foo', 'Title', array( 1 ) );
$field2 = new CMB_Text_Field( 'bar', 'Title', array( 2, 3 ), array( 'repeatable' => true ) );

$group->add_field( $field1 );
$group->add_field( $field2 );
Expand Down Expand Up @@ -39,22 +39,29 @@ function testGetValues() {
function testParseSaveValues() {

$group = new CMB_Group_Field( 'group', 'Group Title', array() );
$field1 = new CMB_Text_Field( 'foo', 'Title', array( 1, 2 ) );
$field2 = new CMB_Text_Field( 'bar', 'Title', array( 3, 4 ) );
$field1 = new CMB_Text_Field( 'foo', 'Title', array( 1 ) );
$field2 = new CMB_Text_Field( 'bar', 'Title', array( 2, 3 ), array( 'repeatable' => true ) );

$group->add_field( $field1 );
$group->add_field( $field2 );

$group->set_values( $values = array(
$group->set_values( array(
'group' => array(
'foo' => array( 1, 2 ) ,
'bar' => array( 1, 2 )
'foo' => array( 1 ),
'bar' => array( 2, 3 )
),
) );

$expected = array(
'group' => array(
'foo' => 1,
'bar' => array( 2, 3 )
)
);

$group->parse_save_values();

$this->assertEquals( $group->get_values(), $values );
$this->assertEquals( $group->get_values(), $expected );

}

Expand Down