knockout.files icon indicating copy to clipboard operation
knockout.files copied to clipboard

Binding handler doesn't execute if I try to upload same file twice

Open PhillyWebGuy opened this issue 9 years ago • 3 comments

It appears the binding handler doesn't execute if I try to upload the same file twice, but only back to back. If I upload file A, file B, then upload A again, it executes fine. But I try to upload file A then try A again, the binding handler doesn't seem to fire.

PhillyWebGuy avatar Sep 11 '15 19:09 PhillyWebGuy

It looks like the problem is with the fact that the input retains the same value and thus, I suppose, the binding handler doesn't realize that the input has changed, so it won't fire.

In the binding hander, it looks like you need to pass the element to the loadedCallBack:

reader.onload = function (fileLoadedEvent) {
     loadedCallback(file, fileLoadedEvent.target.result, element);
};

And, then in your callback:

yourCallBack = function (fileMetaData, uploadData, target) {
       //do stuff with the data
        $(target).val(''); //In case you need to upload same file twice
};

PhillyWebGuy avatar Sep 11 '15 19:09 PhillyWebGuy

Hey, if you solve it then just push up a merge request and I will get it merged in.

grofit avatar Sep 11 '15 22:09 grofit

PhillyWebGuy: Yep, this seems to be the case. Since you havn't pushed it, I didn't want to change knockout.files.js, so I just added this to my callback funciton: $('#image_files').val('');

tonygustafsson avatar Oct 14 '15 12:10 tonygustafsson