Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Nested GridField issue


Go to End


3 Posts   892 Views

Avatar
Faloude

Community Member, 55 Posts

4 February 2017 at 9:59am

Edited: 04/02/2017 10:00am

When you have nested GridFields, the following issue arrises.

Suppose a Page has_many Teams which has_many Players. When you add a new Team you can see the next gridfield which holds the Players. In order to add Players, you'll have to save the Team first, and then add a Player. Needless to say, this will be a disaster for nooby users as they will add a whole team of players, only to find that they forget to save the Team.

I already have an idea on how to solve it, but I'm eager to hear other methods.

Possible solution: add an entwine hook to the Player "add" button that will save Team. I'm just not sure what happens when there is a validation error, eg when the Team Name (required) isn't filled in.

Avatar
martimiz

Forum Moderator, 1391 Posts

6 February 2017 at 6:24am

The way I usually tackle this is conditionally add the gridfield, kind of like it was before with the fileupload field in 2.x.

So in Team show the gridfield if the team has an ID, and if not, show a message (to add players first save the team).

Avatar
Faloude

Community Member, 55 Posts

6 February 2017 at 7:47am

That's not a bad idea actually :-)