testing with jquery if file has been selected

6 posts, 0 answers
  1. Morten
    Morten avatar
    267 posts
    Member since:
    Jul 2012

    Posted 08 Sep 2014 Link to this post

    how do I test if a file has been selected in a kendo ui upload widget (using jquery)?

    var upload = $("#picture").data("kendoUpload");
    upload.?
  2. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2159 posts

    Posted 09 Sep 2014 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. Morten
    Morten avatar
    267 posts
    Member since:
    Jul 2012

    Posted 09 Sep 2014 in reply to Dimiter Madjarov Link to this post

    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
  5. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2159 posts

    Posted 09 Sep 2014 Link to this post

    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!
     
  6. Morten
    Morten avatar
    267 posts
    Member since:
    Jul 2012

    Posted 10 Sep 2014 in reply to Dimiter Madjarov Link to this post

    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
  7. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2159 posts

    Posted 10 Sep 2014 Link to this post

    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!
     
Back to Top
Kendo UI is VS 2017 Ready