0

so i have searched many questions posted and i cant find the right answer to my problem. Basically, i have an input type file which is multiple, what I want to do is display all the files selected and then for each item there is remove button something like this: enter image description here

Now here's my problem,

How do I update the value of the input type file, when I removed an item in the selected items? and also how will the formdata read the value of the input?

$('.view').on('change', '#form-add-note #file', function(event){
 var files = event.originalEvent.target.files;
  files.forEach(function (file) {
    // do something
   });
});

$('.view').on('click', '#file-attachment-remove', function(e){
        var filename = $(this).data('name');
        // will act as remove item and updates the input value
    });


<div class="row">
  <div class="col-100">
    <label class="file-label button button-big color-black f16 bold link" for="file"><i class="fa fa-paperclip"></i><span class="file-text">Add Attachments</span></label>
    <input type="file" name="addnote-attachment[]" id="file" class="inputfile" multiple="true" />
   </div>        

and after that it needs to update the value of the input too so that the form data will know that i remove and item in the selection, because i use the name attribute for every input i

This question is the most similar but it doesnt solve my problem.. How to remove one specific selected file from input file control

Jarvis Millan
  • 451
  • 1
  • 7
  • 19
  • FormData contains data in the form of an array, if you can get the position of the file within the array (while clicking on the remove button), that will help you to remove the exact file. – Shiladitya May 10 '18 at 08:17
  • i am reffering to the input type file. if i have an array with that input with name="addnote-attachment[]" but since the value of input file is a string – Jarvis Millan May 10 '18 at 08:25
  • Is it possible to keep track of the removed files and ignore them when you submit de data? May be with a removed input – duatis May 10 '18 at 09:50

0 Answers0