nervgh / angular-file-upload

[ALMOST NOT MAINTAINED] Angular File Upload is a module for the AngularJS framework
MIT License
3.43k stars 1.13k forks source link

nv-file-select with multiple attribute problem #525

Open kamilkp opened 8 years ago

kamilkp commented 8 years ago

Hi.

I see in your source code that if an input has multiple attribute; after the file(s) are selected in the file picker you clear out that input's value and also replace it with a clone of itself - this was introduced in this commit

The problem is that cloning an element and passing a true as an argument to clone copies the event handlers only and only if we are on jQuery. It is broken on jqLite. So this results in a behavior that after selecting some file in the filepicker, the input is essentially useless (the clone doesn't have the onChange event listener anymore).

I could provide a jsfiddle, but one quick glance at angular's jqLite implementation of clone should be enough:

function jqLiteClone(element) {
  return element.cloneNode(true);
}
jmkenz commented 8 years ago

Yes I've run into this same issue and took me a while to narrow it down to needing jQuery - thank you for confirming the reason behind this. Will this change be going into the repo?

lordnox commented 8 years ago

Just found and tracked the same bug down. jQuery does a lot of things during cloning... there will not be an easy replacement for the .replaceWith method.

I'd propose removing it when on jQLite.

How did you resolve the issue?

jmkenz commented 8 years ago

So far my only solution has been to use jQuery I'm afraid. I tried including just the core jquery library without any modules to keep file size down, but that messed up my Angular app, which had deactivated jqLite altogether since it recognized jQuery was being used. So it's gotta be the full version of jQuery.

hikirsch commented 8 years ago

it seems if i add a this.bind after the clone it works. to avoid the double binding based on jquery, would it be acceptable to clone just the html and then rebind the element instead? i really don't want this to be the only reason i have jquery in my project.