Skip to content

Commit

Permalink
An empty array can sometimes evaluate falsey. Fix repeat groups getti…
Browse files Browse the repository at this point in the history
…ng "Array" as their value if empty. Fixes #332, Fixes #390.
  • Loading branch information
jtsternberg committed Sep 1, 2015
1 parent ba22951 commit 8ad8b63
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -21,6 +21,7 @@ All notable changes to this project will be documented in this file.
* Fix long-standing issues with radio and multicheck fields in repeatable groups losing their values when new rows are added. ([#341](https://github.com/WebDevStudios/CMB2/pull/341), [#304](https://github.com/WebDevStudios/CMB2/pull/304), [#263](https://github.com/WebDevStudios/CMB2/pull/263), [#246](https://github.com/WebDevStudios/CMB2/pull/246), [#150](https://github.com/WebDevStudios/CMB2/pull/150))
* Fixes issue where currently logged-in user's profile data would display in the "Add New User" screen fields. ([#427](https://github.com/WebDevStudios/CMB2/pull/427))
* Fixes issue where radio values/selections would not always properly transfer when shifting rows (up/down). Props [jamiechong](https://github.com/jamiechong) ([#429](https://github.com/WebDevStudios/CMB2/pull/429), [#152](https://github.com/WebDevStudios/CMB2/pull/152)).
* Fixes issue where repeatable groups display "Array" as the field values if group is left completely empty. ([#332](https://github.com/WebDevStudios/CMB2/pull/332),[#390](https://github.com/WebDevStudios/CMB2/pull/390)).

## 2.1.0 - 2015-00-05

Expand Down
5 changes: 3 additions & 2 deletions includes/CMB2_Field.php
Expand Up @@ -233,8 +233,9 @@ public function get_data( $field_id = '', $args = array() ) {
: get_metadata( $a['type'], $a['id'], $a['field_id'], ( $a['single'] || $a['repeat'] ) );
}

if ( $this->group && $data ) {
$data = isset( $data[ $this->group->index ][ $this->args( '_id' ) ] )
if ( $this->group ) {

$data = is_array( $data ) && isset( $data[ $this->group->index ][ $this->args( '_id' ) ] )
? $data[ $this->group->index ][ $this->args( '_id' ) ]
: false;
}
Expand Down

0 comments on commit 8ad8b63

Please sign in to comment.