diff --git a/classes.fields.php b/classes.fields.php index 2cf43bfd..0b05f2c1 100644 --- a/classes.fields.php +++ b/classes.fields.php @@ -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 ); } } diff --git a/tests/testGroupField.php b/tests/testGroupField.php index e638729a..3287be02 100644 --- a/tests/testGroupField.php +++ b/tests/testGroupField.php @@ -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 ); @@ -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 ); }