purtuga / SPWidgets

Sharepoint Custom UI Widgets
74 stars 34 forks source link

Get the file name of file uploaded #76

Open princyphlp opened 7 years ago

princyphlp commented 7 years ago

Hi, We have the SPWidget Upload control embedded in the edit list form. So we have encountered users selecting file from the desktop, but forget to click on Upload button, instead they submit the edit form with Save Click.

How do we check if the file was uploaded in PreSave function.

purtuga commented 7 years ago

I'm not sure what PreSave is... The Upload widget emits "change" events when the user interacts with it (ref). You can use that to run code when user selects a file, but does not click on the "upload" button. Something like:

$(yourContentEle).SPControlUpload({
   ...
   onPagePage: function(ev){
       if (ev.state === 2) {
           // user selected a file, but upload has not happen yet.
       }
   }
})

You should then be able to track whether the user has actually uploaded the file or not...

/Paul.

princyphlp commented 7 years ago

Tested it, unfortunately this message is fired when I click on the Upload button. 2017-07-28_10-05-35

princyphlp commented 7 years ago

As you can see, I want to check if the file is selected when the Save button is clicked. Users sometimes select the file but ignore to click on the Upload button instead click on Save. I tried with the above recommendation and for if (ev.state = 2) alert("user selected a file, but upload has not happen yet.");

above code is fired when the Upload button is hit.

purtuga commented 7 years ago

Ahh. Ok. Then the event you need does not exist today in this widget. It would have to be enhanced to support emitting an event as soon as the user selected a file and maybe have a method that you could use to detect if a file was picked (hasFileSelected()). I can't promise a timeline, but if I get some time I will try to look into it.

Paul

-- sent from mobile