Best way to change fileList in Javascript

157 Views Asked by At

Im making an web app for my ojt and they require me to add a delete function to a file field. Like if I choose to upload 3 of them there would be a preview to those file and I can remove some of them.

Can I just edit the fileField? Example document.getElementbyID("field").files returns a filefield Can I change that?

if not what is the best way to do it.

1

There are 1 best solutions below

1
Peterrabbit On

Create a FormData object from your form Element and use it to handle the fields

const form = document.getElementById("your_form");
const data = new FormData(form);
data.delete("file_field_name");