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.

Form Questions /

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

Issues when using UploadField


Go to End


3 Posts   1274 Views

Avatar
Nobi

Community Member, 5 Posts

27 October 2012 at 7:46am

I am using UploadField on a Dataobject editor with getCMSFields()

There is some issues when Create New Data. I upload a file when this new data have not been save. Its shows success upload like the screenshot I've attached.

But when, I back to the Grid list form, then I edit the last created data, it is show me no image uploaded in UploadField input.

I don't know why, but I guess the first image uploaded failed to linked to Dataobject because it's don't yet exist. When I save it, the Dataobject ID was created, and when I upload an image it success to linked Dataobject ID and Image file ID.

Its supposed to be an easy task, I just want to disabled UploadField when the data has not been created yet, but in SS 3.0 I doesn't have idea how to do this ?

Can anyone help me to solved this ?

Thanks.

Attached Files
Avatar
lx

Community Member, 83 Posts

28 October 2012 at 7:17pm

You are right, the uploadfield doesnt support to add an image to a dataobject that does not yet exist.
I hope this feature will be added in the future. Bye i talked to zauberfisch , the author of uploadfield, in irc about it. He said that would like to add this feature but has not enough time to do it at the moment.

So what you can do is:

If ($this->ID) {
New uploadfield();
}
Else {
New readonlyfield(...., "you need to save this record, before you can add an image");
}

Avatar
Johan

Community Member, 49 Posts

30 October 2012 at 10:55pm

Edited: 30/10/2012 11:30pm

It should work well enough and If you do not want the items to go live without an image then I guess a quick fix would be:

           <% if Image %>
                   
                    <!-- content here -->

            
                    <% else %>
                    <% end_if %>