primeng icon indicating copy to clipboard operation
primeng copied to clipboard

Files not removed correctly in file upload

Open supriya2992 opened this issue 9 years ago • 7 comments

I'm submitting a ... (check one with "x")

[X] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35

Plunkr Case (Bug Reports) http://www.primefaces.org/primeng/#/fileupload

Current behavior When we select multiple files for upload, and try deleting a file other than first, it is not removed; instead first file is removed.

Expected behavior Selected file should get deleted.

Minimal reproduction of the problem with instructions

  1. Select 2 or more files in file upload.
  2. Delete second file. (first file will get deleted!!)

What is the motivation / use case for changing the behavior? In fileupload.js file, the index i that is passed as an argument to remove function is not defined anywhere in html. let i = index needs to be added in the code.

Please tell us about your environment:

  • Angular version: 2.0.X
  • PrimeNG version: 1.1.0
  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
  • Language: [all | TypeScript X.X | ES6/7 | ES5]

  • Node (for AoT issues): node --version =

supriya2992 avatar Dec 29 '16 09:12 supriya2992

Could it be that you have single selection mode? I have the same issue with single selection mode and surprisingly I can select multiple images with multiple=false. When I delete the last selected item then the first disappears like you described. I don't know if this is connected.

sittingbool avatar Jan 04 '17 10:01 sittingbool

the primeng code is wrong. If you check their fileupload,js file's template code, they have passed i as argument to remove() function but have not initialized 'i' in ngFor.

supriya2992 avatar Jan 05 '17 11:01 supriya2992

As already mentioned, the index (i) passed to remove is not initialized. The *ngFor needs to be: *ngFor="let file of files; let i = index;".

brian428 avatar Feb 02 '17 00:02 brian428

In the meantime, you can work around this by using @ViewChild() in your component to get a reference to the FileUploader (I'm naming it fileUpload in the below example), then specify a custom file template:

<template let-file let-i="index" pTemplate="file">
  <div class="ui-fileupload-row">
    <div><img [src]="file.objectURL" *ngIf="fileUpload.isImage(file)" [width]="fileUpload.previewWidth" /></div>
    <div>{{file.name}}</div>
    <div>{{fileUpload.formatSize(file.size)}}</div>
    <div><button type="button" icon="fa-close" pButton (click)="fileUpload.remove(i)"></button></div>
  </div>
</template>

brian428 avatar Feb 02 '17 01:02 brian428

Do you have a full example of using the template, because I want to use the same for changing the filesize string, which is working but when I click on the remove button I get 'Cannot read property 'remove' of undefined' This is my current code: <p-fileUpload name="fileUpload" url="{{url}}" multiple="multiple" (onBeforeSend)="onBeforeSend($event)" (onError)="onError($event)" chooseLabel="XML-bestanden kiezen" cancelLabel="Annuleren" accept=".xml" maxFileSize="50000000"> <template let-file let-i="index" pTemplate="file"> <div class="ui-fileupload-row"> <div>{{file.name}}</div> <div>{{fileUploadFormatSize(file.size)}}</div> <div><button type="button" icon="fa-close" pButton (click)="fileUpload.remove(i)"></button></div> </div> </template> </p-fileUpload>

pmeems avatar Feb 18 '17 10:02 pmeems

@cagataycivici , @Mrtcndkn The fix is easy, please fix it, I have to fix it manually every time I update primeng

jmesa-sistel avatar Feb 22 '17 12:02 jmesa-sistel

Fixed by adding the index definition to ngFor, thank you.

cagataycivici avatar Feb 22 '17 12:02 cagataycivici