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.

Customising the CMS /

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

Upload Field issue


Go to End


5 Posts   2116 Views

Avatar
Neelam

Community Member, 15 Posts

21 November 2012 at 9:51pm

Edited: 22/11/2012 2:20am

I am using SilverStripe 3.0

I am using UploadField to enable file upload from Silverstripe admin

I have written the following code in my custom Page Type:

//has_one array
static $has_one = array(
"MyIcon1" => "File"
);

//in getCMSFields
$fields->addFieldToTab("Root.Images", new UploadField('MyIcon1'));

My problem is that on a direct first page load, the upload does not work i.e. if you refresh the page or if you go to this page by typing its url, the file browser window is shown and after you select the file it only closes the file browser does not upload anything.....This happens in mozilla firefox only..

if u go to some other page and come back that is after ajax page loads it starts working....

Any help will be appreciated...Thanks in advance...

Avatar
Neelam

Community Member, 15 Posts

23 November 2012 at 11:44pm

I was trying to follow the flow of UploadField.js and by adding alert is making the upload work properly on the first load also:

line no 59 approx. in framework/javascript/UploadField.js

$.entwine('ss', function($) {

$('div.ss-upload').entwine({

Config: null,

onmatch: function() {
alert('match');

Can someone please explain the reason..is there any particular event which is fired when i am alerting something....is there something that i can do on similar lines to make the upload work without alerting???

Avatar
martimiz

Forum Moderator, 1391 Posts

2 January 2014 at 8:52am

I'm having this same issue now in 3.1.2 in FireFox 26 on Mac on first load.

After reloading the CMS, the FileUpload doesn't work. No javascript call is made, no error. Switching to another menu item and then coming back, or first saving (=updating) the record makes it work. Adding your alert to UploadField.js also does the trick on first load.

The issue seems to be with this line UploadField.js ~#165:

var fileInput = this.find('.ss-uploadfield-fromcomputer-fileinput');

Placing the alert directly before this line makes it work, directly after this line no longer. Could it be some sort of timing issue, where ss-uploadfield-fromcomputer-fileinput cannot be found because it doesn't exist yet? This is in a scaffolded UploadField on a LeftAndMain extension.

Have you (or anyone) ever found out how to avoid this?

Martine

Avatar
martimiz

Forum Moderator, 1391 Posts

3 January 2014 at 4:47am

Edited: 03/01/2014 4:57am

I seem to have 'fixed' the problem by wrapping the javascript in document.ready:

framework/javascript/UploadField.js

(function($) {
	$( document ).ready(function() {        // <-- ADDED
		...
	});                                     // <-- ADDED 
});

Can you confirm this?

Martine

Avatar
IQcory

Community Member, 2 Posts

8 May 2015 at 4:07am

martimiz, that fix does work.

This needs to be fixed in the release version. I can't believe it's still a problem over 2 years later.