purtuga / SPWidgets

Sharepoint Custom UI Widgets
74 stars 34 forks source link

Site scrolls to UploadControl on init #77

Closed NoahMueller closed 7 years ago

NoahMueller commented 7 years ago

Hey there,

I got a question, because I am not sure whether it was intended or a bug.

I tried to implement your UploadControl and it works very well. So thanks for that first of all.

But when I used the Upload on the bottom of my site I had to observe that the site scrolls down when the upload is initiated.

Is this a known issue? And if so: Is there a legit work-around? Is there an event which I could use to scroll to the top when the upload is ready?

Thanks in advance and best regards Noah Müller

You can find my minimal example (only HTML-file) in the ZIP-file of the attachements. UploadMinimaltest.zip

purtuga commented 7 years ago

Hi @NoahMueller . I think I have heard of this happening before... The issue is likely caused by the fact that SharePoint automatically sets focus on the file input field on the Upload page and since I'm displaying that in an iframe with this widget, that is likely what is happening. Try this (warning: I have not tested it):

$("#file_upload")
    .bind("focus", function (e) {
        e.preventDefault();
    })
    .SPControlUpload({
        listName: "{LIST-ID}",
        selectFileMessage: "Please select a file",
        overwrite: true,
        debug: false,
        webURL: "URL",
        onUploadDone: function (file) {
            console.log("Uploaded fileObj", file)
        }
    });

Hope this works for you.

NoahMueller commented 7 years ago

Thanks @purtuga for the quick answer.

I tried your tip, but unfortunately it did not work out. I am now gonna go for a workaround displaying the upload-control on the upper part of the site.

Still, thanks a lot! Noah Müller

purtuga commented 7 years ago

Thanks for letting me know... Its hard to say what is causing the page to scroll... Sorry I can't help further. Good luck