pqina / vue-filepond

🔌 A handy FilePond adapter component for Vue
https://pqina.nl/filepond
MIT License
1.93k stars 128 forks source link

Get id on updatefiles from multiple instances #149

Closed santicros closed 4 years ago

santicros commented 4 years ago

Hello!!

I have a page with multiple dynamic instances of filepond, where the user should be able to add more or delete them (they are files for different sections).

I'm using the @updatefiles method, but is there a way to pass a custom id or get it from the filepond ref? Now I have it as @updatefiles=handleFilePondUpdateFile, but with this I don't know from which instance is the file coming from.

If i do @updatefiles=handleFilePondUpdateFile(id) i lose the information coming from updatefiles.

Thanks so much!

santicros commented 4 years ago

If it can help anyone, for now the fix I've found is to use the event listeners of the Filepond instance, not from Vue.

Something like:

const filepondsArray = document.getElementsByClassName(
    "filepond--root"
);

filepondsArray.forEach((filepond) => {
    filepond.addEventListener(
        "FilePond:updatefiles",
        this.listenFileChanges
    );
});

And then I have a method:

methods: {
    listenFileChanges(e) {
        console.log("File modified event", e);
        console.log("File modified, file detail", e.detail);
    }
}
rikschennink commented 4 years ago

@santicros glad to read you found a workaround 👍

rikschennink commented 4 years ago

closed because inactive