This is a migrated thread and some comments may be shown as answers.

testing with jquery if file has been selected

5 Answers 400 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Morten
Top achievements
Rank 1
Iron
Iron
Veteran
Morten asked on 08 Sep 2014, 05:40 PM
how do I test if a file has been selected in a kendo ui upload widget (using jquery)?

var upload = $("#picture").data("kendoUpload");
upload.?

5 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 09 Sep 2014, 08:08 AM
Hello Morten,


You could get the selected files list elements by the k-file class, that is assigned to each of them.
E.g.
var len = upload.wrapper.find(".k-file").length;
 
if(len === 0) {
   //no file selected
}

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
Morten
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 09 Sep 2014, 01:39 PM
Hi Dimiter

thanks for your reply. I'll do so, however, it could be great with a couple of new events on the upload widget:

selected (fired when all files have been added and the widget updated).
removed (fired when all files have been removed and the widget updated).

/Morten
0
Dimiter Madjarov
Telerik team
answered on 09 Sep 2014, 02:05 PM
Hello Morten,


I am not exactly sure what do you mean by "all files have been added". Even when multiple files are selected at once, the select event will be fired, receiving an e.files parameter representing the current files. The second requirement could be implemented with a check in the remove event.

I wish you a great day!

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
Morten
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 10 Sep 2014, 09:27 AM
hi Dimiter,
in the select/remove events (of any of my 6 individual upload widgets on the form) I'm checking if the form is valid using jquery.
Part of the validation is checking that all required upload widgets has a selected file. I'm checking if a required upload widget has a file by checking for "k-file" (as you pointed out). Trouble is (I think) that the "k-file" has not been added to the upload widget markup at time of "select event".

To handle this I using a simple settimeout, however, if the widget had an event like "render complete" / "all files added" I could put my code here. Hope I'm clear. And btw I love working with kendoui. ....i.. great work.

/Morten
0
Dimiter Madjarov
Telerik team
answered on 10 Sep 2014, 10:24 AM
Hello Morten,


Thank you for the clarification and for the nice words. I will pass the suggestion to the developers team. Indeed at the moment using a setTimeout call is the suggested approach.

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Upload
Asked by
Morten
Top achievements
Rank 1
Iron
Iron
Veteran
Answers by
Dimiter Madjarov
Telerik team
Morten
Top achievements
Rank 1
Iron
Iron
Veteran
Share this question
or