Trigger and Upload from OnClick

3 Answers 3623 Views
Upload
Keith
Top achievements
Rank 1
Keith asked on 29 Feb 2012, 06:20 PM
Hello,
We want to give the users the ability to upload documents and then click on a button which says upload; this will call a js function that will ask them to verify or acknowledge that the documents they're about to upload are in the correct format/valid signatures etc. and then on approval of this asynchronously submit the upload. 

Is this possible? 

Thank you.
Keith

3 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 01 Mar 2012, 03:53 PM
Hello Keith,

You can use the following approach - in the Upload's select event, locate the generated Upload button and attach a click handler to it, which will execute your custom logic.

$(document).ready(function() {
    $("#UploadID").kendoUpload({
        async: {
            autoUpload: false
        },
        select: attachClickHandler
    });
});
 
function attachClickHandler(e)
{
    window.setTimeout(function() {
        $(".k-upload-selected").click(function(e) {
            // custom logic
            if (false) {
                e.preventDefault();
                return false;
            }
        });
    }, 1);
}

If you need to reference the input fields to get their values, use

$("#UploadID").data("kendoUpload").wrapper.find("input[type='file']")

Greetings,
Dimo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Alberto
Top achievements
Rank 1
commented on 07 Jun 2013, 06:21 PM

Hi,
I'd like to not use the built in button to tirgger the upload. I'd like to do it with another button.
What I'm doint is to hide the built in button
$(".k-upload-selected").hide()

And trigger its click when clicking my button.
$(".k-upload-selected").click()

Is there a cleaner way?
I didn't find any method to call or event to trigger the upload.

Thanks and regards
Dimo
Telerik team
commented on 10 Jun 2013, 07:49 AM

Hello Alberto,

We will probably provide an API method to trigger an upload in the near future. In the meantime, you can safely use the suggested approach.

Regards,
Dimo
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Alberto
Top achievements
Rank 1
commented on 11 Jun 2013, 03:15 PM

Thanks Dimo
Kyle Smith
Top achievements
Rank 1
commented on 10 Nov 2014, 06:48 PM

Has this API option been added? I don't see it.
Dimo
Telerik team
commented on 11 Nov 2014, 09:40 AM

Hello Kyle,

The discussed API method is still not available, due to the relatively low demand this feature has, compared to others, which we have worked on. You can submit a feature request and vote for it at our feedback portal, in order to raise the priority of the task:

http://kendoui-feedback.telerik.com/

Regards,
Dimo
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Vladimir
Top achievements
Rank 1
commented on 23 Mar 2016, 09:48 AM

Hello Dimo,

  I see that the method has not yet been added.I'm trying to resolve following scenario:

Imagine "windows explorer" UI, where the folders tree on left supports drag&drop of files directly on the folders. This should show upload dialog (ui-modal) where the kendo-upload control is located and start the actual upload.

I'm at a point where I have the event object containing the uploaded files, but I don't know how to pass it onto the kendo-upload to trigger the upload process. 

Can you please suggest solution for this?

Thanks,

Vladimir

Dimiter Madjarov
Telerik team
commented on 23 Mar 2016, 12:52 PM

Hello Vladimir,

Manually passing the files for uploading is not supported by the widget. The file selection should be initiated by the user in order to start the upload process.

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Artur
Top achievements
Rank 1
answered on 24 Jul 2015, 08:09 AM

Would the following code:

$('#fileUpload​').getKendoUpload().trigger('upload') 

with the "upload" event handler configured, do the trick?

But I agree - I reckon the implementation of the Upload widget simply not finished. Wouldn't it be a matter of just wrapping a couple of code lines (that must have already been in there), into a method helper? :) Please add it without asking people for feedback ranking. Please please please.

Dimo
Telerik team
commented on 24 Jul 2015, 10:30 AM

Hi Artur,

Triggering the Upload event manually will not start the upload process, because the logic is the other way around - the upload process triggers the event.

Regards,
Dimo
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Artur
Top achievements
Rank 1
commented on 24 Jul 2015, 12:24 PM

Yes, correct. It only looks like working in that the event is actually triggered, but is empty (does not carry e.filescollection for example).
yula
Top achievements
Rank 1
commented on 16 Nov 2015, 12:30 PM

Hello,

I have a similar issue - I would like to generate a click on the select button that will be fired on the window upload - how can that be done?

Thank you,

                 Yulia.

yula
Top achievements
Rank 1
commented on 16 Nov 2015, 12:32 PM

Hi, 

I would like to generate a click on the select button (to open a window from which the file will be selected) on document lod. What is the best way to achieve it?

Thank you,

                    Yula.

yula
Top achievements
Rank 1
commented on 16 Nov 2015, 12:32 PM

Hi, 
I would like to generate a click on the select button (to open a window from which the file will be selected) on document lod. What is the best way to achieve it?
Thank you,
                    Yula.
Dimiter Madjarov
Telerik team
commented on 18 Nov 2015, 09:12 AM

Hello Yula,

This behavior is not supported due to browser security restrictions. The selection of the file has to be triggered by user interaction, not via JavaScript.

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Vladimir
Top achievements
Rank 1
answered on 27 Mar 2016, 11:20 PM

Just in case anyone needs this, I've found a way of implementing it.

Dojo is not working for some reason, so here is code fragment:

<div id="mydrop">
   (drop files here)
</div>
<input type="file" name="files" id="upload" />

And this is JS fragment - I'm using the "_onDrop(e)" function found within the source code of kendo upload :)

var mydrop = $("#mydrop");
var upload = $("#upload").data("kendoUpload");
 
function myOnDrop(e) {
  e.stopPropagation();
  e.preventDefault();
  if (isFileDragDropEvent(e)) {
    var files = e.originalEvent.dataTransfer.files;
    mydrop.text("Droped: " + files.length + " files");
    // this is the trick
    upload._onDrop(e);
  }
}
 
function isFileDragDropEvent(e) {
  var dt = e.originalEvent.dataTransfer;
  return (dt.types != null && ($.inArray("Files", dt.types) !== -1 || dt.types.contains("application/x-moz-file")));
}
 
 
$(document).ready(function () {
            mydrop.on("drop", myOnDrop);
});
 

 

Thanks,

Vlad.

Tags
Upload
Asked by
Keith
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Artur
Top achievements
Rank 1
Vladimir
Top achievements
Rank 1
Share this question
or