Cmb2: Possibility to add groups inside a group

Created on 11 Dec 2015  路  6Comments  路  Source: CMB2/CMB2

It would be useful to have the possibility to add groups recursively.

For example:

$group_field_id = $cmb2->add_field( array(
    'id' => 'my_group_id',
    'desc' => 'Group',
    'type' => 'group',
) );
$cmb2->add_group_field( $group_field_id, array(
    'id' => 'my_group_element_id',
    'name' => 'Group Element',
    'type' => 'text',
) );
$subgroup_field_id = $cmb2->add_group_field( $group_field_id, array(
    'id' => 'my_subgroup_id',
    'desc' => 'Subgroup',
    'type' => 'group',
) );
$cmb2->add_group_field( $subgroup_field_id, array(
    'id' => 'my_subgroup_element_id',
    'name' => 'Subgroup Element',
    'type' => 'text',
) );

Gives the following error:

( ! ) Warning: array_key_exists(): The first argument should be either a string or an integer in \cmb2\includes\CMB2.php on line 887

$subgroup_field_id is an array with

  • [0] -> parent_id
  • [1] -> created_group_id

Using $subgroup_field_id[1] in the code below removes the warning, but the sub group elements still don't show (see below screenshot).

$cmb2->add_group_field( $subgroup_field_id[1], array(
    'id' => 'my_subgroup_element_id',
    'name' => 'Subgroup Element',
    'type' => 'text',
) );

cmb2-subgroups-issue-151211

I guess this feature would need quite a bit of rewriting of the code logic that would certainly have impacts on other functions and uses, but I guess the 2 main tasks would be:

  • [ ] add_group_field and add_field code would probably need to be fixed to handle the new recursive array and field logic.
  • [ ] I also suspect that the "update field value" and "get field value" handling functions would need to be fixed to make the sub groups work.

Meanwhile, a user could extends the CMB2 class and rewrite the needed functions to handle recursive groups.

Feature Request enhancement help wanted

Most helpful comment

Any updates on this?

All 6 comments

Any updates on this?

related #565

Any updates on this issue. Please share if you guys found any alternative.

do you have full example of how to do custom fields + repeatable + save data correctly?

do you have full example of how to do custom fields + repeatable + save data correctly?

I have the same question

Hi guys, can you do it? :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bomsn picture bomsn  路  5Comments

angelorocha picture angelorocha  路  6Comments

mathetos picture mathetos  路  8Comments

needtakehave picture needtakehave  路  7Comments

gorirrajoe picture gorirrajoe  路  4Comments