Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileUpload: multiple=false but could add more than one file #6422

Open
hrynevychroman opened this issue Sep 17, 2024 · 1 comment
Open

FileUpload: multiple=false but could add more than one file #6422

hrynevychroman opened this issue Sep 17, 2024 · 1 comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working

Comments

@hrynevychroman
Copy link

Describe the bug

primevue-multiple-false-issue.mp4

I will open a fix PR

Reproducer

https://stackblitz.com/edit/zfjexy?file=src%2FApp.vue

PrimeVue version

4.0.7

Vue version

3.x

Language

TypeScript

Build / Runtime

Vite

Browser(s)

All Browsers

Steps to reproduce the behavior

No response

Expected behavior

No response

@hrynevychroman hrynevychroman added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Sep 17, 2024
@tugcekucukoglu tugcekucukoglu added Type: Bug Issue contains a bug related to a specific component. Something about the component is not working and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Sep 25, 2024
@CCodam
Copy link

CCodam commented Oct 12, 2024

I think there's a misunderstanding about what the multiple prop is supposed to do.
According to the documentation, if set to true, "Used to select multiple files at once from file dialog.", which it accomplishes.
When set to false (default), you're not able to select multiple files in the browser dialog nor drop multiple files into the upload area at once. You can however, as you've shown, browse/drop one file at a time, multiple times. This is the intended functionality, as I understand it.

If you want to limit the actual number of files allowed to be uploaded, you should use the fileLimit prop instead https://primevue.org/fileupload/#api.fileupload.props.fileLimit
Unfortunately the code does not prevent you from uploading past the fileLimit, it merely disables the upload button.
The FileUpload Template example that your code is based on, uses its own upload button, that does not comply with the fileLimit.

Tip

Rough fix of the FileUpload Template example, when using fileLimit.

Apply :fileLimit="1" to the component, add uploadedFiles to the header slot, then modify the :disabled prop of the upload button to

!files || files.length === 0 || files.length > 1 || (uploadedFiles && uploadedFiles.length === 1)

...and for a better UX add a :disabled prop to the browse button

(files && files.length >= 1) || (uploadedFiles && uploadedFiles.length === 1)

Please be aware, that the value of 1, in the above examples, needs to be manually changed when changing the fileLimit of the FileUpload component.

Important

The actual issue is that the FileUpload component relies on the disabled state of the upload button, instead of cancelling the upload procedure when the fileLimit would otherwise be breached.
All the necessary code is there, it's even used to cancel the auto upload here

if (this.auto && this.hasFiles && !this.isFileLimitExceeded()) {

The check should instead reside within the uploader() function, so that both auto and manual uploads are checked against isFileLimitExceeded()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants