Upload - last item removal

4 posts, 0 answers
  1. Paul
    Paul avatar
    9 posts
    Member since:
    Feb 2014

    Posted 31 Mar 2014 Link to this post

    This feels like it should be a simple question, but I can't find the answer anywhere.

    If a user clicks the remove button (x) on the only file in an upload list, the file is removed from the list and the 'upload' button is hidden. How can I simulate this?

    I'm overriding the 'onselect' event and checking for existing files in a directory. If the user selects 'no, I don't want to replace the existing file', I'm removing the item from the upload list successfully, but if it's the only file in the list, I'm left with the button and a border around the empty list.

    Thanks in advance.
  2. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2159 posts

    Posted 01 Apr 2014 Link to this post

    Hi Paul,

    The easiest approach in the current case would be to trigger the click event of the remove button of the list item. This way the widget will automatically check if the file list is empty and apply the appropriate changes.
    E.g.
    $(".k-upload").find(".k-file .k-delete").closest("button").click()

    Regards,
    Dimiter Madjarov
    Telerik
     

    Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

     
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Paul
    Paul avatar
    9 posts
    Member since:
    Feb 2014

    Posted 01 Apr 2014 in reply to Dimiter Madjarov Link to this post

    Thanks Dimiter,

    Your response gave me the information I needed. I had access to the name of the file I wanted to delete, so I've modified your code to achieve the desired result, as follows:

    function removeFile(fileName) {
     
        var li = $(".k-upload-files").find("[title='" + fileName + "']").parent();
     
        $(li).find(".k-delete").closest("button").click()
     
    }


    Paul
  5. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2159 posts

    Posted 01 Apr 2014 Link to this post

    Hi Paul,

    I am glad that the issue is resolved. Do not hesitate to contact us again if further issues arise.

    I wish you a great day!

    Regards,
    Dimiter Madjarov
    Telerik
     

    Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

     
Back to Top
UI for ASP.NET MVC is VS 2017 Ready