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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

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

Show Tab or Field after Saving - DataObject


Go to End


4 Posts   1331 Views

Avatar
Phils

Community Member, 11 Posts

29 November 2013 at 1:15am

Edited: 29/11/2013 1:15am

Hi everybody,

I got a DataObject with some has_many Relations. I know, that the DataObject has to be saved first, before you can add the related Object with a Gridfield (like you have to save first before you can add Images with a Uploadfield).

My Question is, if I can hide the Gridfield and/or the Tab where my Gridfield is in until the DataObject is saved. So that the Editor doesn't get confused.

How does the UploadField work, which first shows a message and after saving the Dataobject shows the possibility to Upload?

Thanks in advance,
Philip

Avatar
martimiz

Forum Moderator, 1391 Posts

5 December 2013 at 1:13am

i don't know if this would work, but just maybe you could hide the field in the DataObjects getCMSFields() if the $this->ID is empty?

Martine

Avatar
zenmonkey

Community Member, 545 Posts

7 December 2013 at 3:58pm

I'm pretty sure as of 3.1.x creating a new DataObject creates a draft object so you can actual do relations before saving at least for images. I wrap the fields I want to hide in if $this->ID != 0 since the draft object actually has an ID of 0.

Avatar
Phils

Community Member, 11 Posts

11 January 2014 at 12:55am

Thank you both.
Everything works fine now.
Wrapped my Tabs and fields in:

if ($this->ID != 0){
}