Cmb2: Will CMB2 support nested Group Field?

Created on 15 Jan 2016  路  34Comments  路  Source: CMB2/CMB2

Will you guys ever support nested group field?

Feature Request

Most helpful comment

Everyone who sees this and is tempted to add a +1 comment: please, please, please do not. That needlessly pings people who are subscribed to issues on this repo. Just go hit the thumbs up on the OP above to show your support for this feature request, please.

All 34 comments

Follow.

follow.

Follow too

Follow

+1

please add nested group fields

would be cool

+1

This would be amazing and super useful.

Any good news?

Nothing I've heard of, I imagine this ticket will be updated as appropriate at the time.

+1

+1

+1

would be awesome!

+1
I've always missed this feature

馃憤

Really need it. Any body can help?

+1

+1

Everyone who sees this and is tempted to add a +1 comment: please, please, please do not. That needlessly pings people who are subscribed to issues on this repo. Just go hit the thumbs up on the OP above to show your support for this feature request, please.

馃憤 I second that, @tnorthcutt.

馃憤 Good point, @tnorthcutt

馃憤 @tnorthcutt

I see #278 was opened 3 years ago. Is there any progress being made towards nested groups? This would be a killer feature, and I need it badly for a project.

I would love to help, is there a branch that I can look at that is being worked on?

None I'm personally aware of. When in doubt, feel free to create your own branch.

Do you know where the primary pain point is? Like, what is main reason it's not easy?

Easiest one to pinpoint for me would be the JavaScript needed to make it happen, and making sure it all saves accurately. I know max_input_vars PHP configuration settings can start presenting issues as well, especially as suddenly large groups start duplicating regularly. Things to consider

From what I am seeing when I attempt to create a nested group, it will not render the child group at all. I don't think JavaScript even comes into play in the initial field rendering, or am I wrong about that?

I feel like the problem is more related to add_group_field in includes/CMB2.php. Specifically lines 1524 - 1528:

        $this->_add_field_to_array(
            $field,
            $this->meta_box['fields'][ $parent_field_id ]['fields'],
            $position
        );

It appears that it doesn't support arbitrary number of parents. I think what it might need to do is get the array first, determine the nesting order of the parent, then append.

I think one of two changes might need to happen to get past this step:

  1. First do a recursive search in the meta_box['fields'] array for the $parent_field_id to determine exactly where the child field should be appended. This would require that child field IDs be unique ( currently they are not ). Or,
  2. Change the add_group_field to accept another parameter that dictates the child field position. The parameter could be optional to avoid any breaking change, falling back to the current behavior if the parameter is omitted.

I think either option would have pros / cons. The first option is probably cleaner, but could mean name collisions unless people were pretty careful.

The second option, I am not quite sure what that would look like yet. public function add_group_field( $parent_field_id, array $field, $position = 0, $depth = 0 ) perhaps? I think an additional check would need to be made to determine if the $parent_field_id exists at $depth - 1. Or maybe $depth should be $parent_field_depth.

Anyway, that is the first hurdle I see, not sure if that would at least get the child group fields to render.

Thoughts?

I don't personally have answers for this, as I'm primarily frontline support, and not really in the guts of development here :)

@jtsternberg perhaps you can shed some light on all of this?

@tw2113 has there been any further discussion around this topic? I just ran into it again with a project that I would love to use CMB with but this is a major blocker and I don't know exactly where to start. I'd love to start working on a patch ( won't solve my immediate problem, but seems like a much needed feature ).

Nothing I've heard of or been involved with.

Add info in docs, at least...

Here's for anyone in desperate need: Carbon Fields supports this without any limitations. It works nicely alongside CMB2.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DevinWalker picture DevinWalker  路  4Comments

jquimera picture jquimera  路  8Comments

cehojac picture cehojac  路  3Comments

alanef picture alanef  路  4Comments

GaryJones picture GaryJones  路  3Comments