Re-apply HTML5 Filter After Removing File

2 posts, 0 answers
  1. Michael
    Michael avatar
    23 posts
    Member since:
    Sep 2014

    Posted 21 Feb 2017 Link to this post

    I am using $('.ruFileInput').attr('accept', 'image/*'); to apply a filter on an AsnycUpload control with MaxFileInputsCount set to 1. This works great on initial load, but if a user removes the file and clicks to upload a new one, the filter is no longer applied.  I tried using the same jQuery code to re-apply the filter in the OnClientFileUploadRemoved event, but the ruFileInput element hasn't been recreated at this point, so it doesn't work.  Any ideas on how else I can re-apply the filter after a file is removed?

  2. Peter Milchev
    Peter Milchev avatar
    589 posts

    Posted 24 Feb 2017 Link to this post

    Hello Michael,

    Wrapping the attribute setting logic in a function called by setTimeout should allow the input to render before executing the attribute logic:

    function OnClientFileUploadRemoved() {
        setTimeout(function () {
            $telerik.$('.ruFileInput').attr('accept', 'image/*');

    Here is a forum thread that would help you better understand what the setTimeout function achieves: Why is setTimeout(fn, 0) sometimes useful?

    Peter Milchev
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top