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: Control internal files state #3750

Closed
harsha16208 opened this issue Dec 7, 2022 · 2 comments · Fixed by #3751
Closed

FileUpload: Control internal files state #3750

harsha16208 opened this issue Dec 7, 2022 · 2 comments · Fixed by #3751
Assignees
Labels
Type: New Feature Issue contains a new feature or new component request
Milestone

Comments

@harsha16208
Copy link

harsha16208 commented Dec 7, 2022

Describe the feature you would like to see added

I would like to request you introduce a possible approach for handling the state of the FileUpload Component as this helps the developers select only certain files which pass their validations and let them upload.

Is your feature request related to a problem?

I see there is no way of updating the state of the FileUpload component as it leads to an uncontrolled state for the number of files you are uploading or if you want to validate files based on certain criteria (like extensions) and want to reject invalid files.

If the state of the FileUpload component is unmanageable from an external component it leads to the unnecessary rendering of invalid files and we can't restrict users from uploading files within the limit.

Our problem statement is we want the user to upload only 3 files at a maximum and only certain extensions are valid but after performing our validations we are unable to manage the state of the FileUpload component thus resulting in uploading all the files selected by the user.

This is our file upload component

image

We accept only certain extensions of image format (gif|jpe?g|tiff?|png|webp|bmp) however see when we select .txt files they are also being rendered

image

Invalid files are rendered and unable to control the state of FileUpload

image

Also, you have mentioned in the forum to use the onSelect handler but I observed that the onSelect handler gets the event param which contains the FileUpload component's previous state and thus cannot validate the current selection.

image

image

image

On selecting files and when onBeforeSelect is triggered the event contains No files

image

When selecting multiple files and trying to validate in onBeforeSelectHandler returning false from the handler cancels the entire selection but not the invalid file selected.

Describe the solution you'd like

No response

Describe alternatives you have considered

No response

Additional context

No response

@harsha16208 harsha16208 added Status: Discussion Issue or pull request needs to be discussed by Core Team Type: New Feature Issue contains a new feature or new component request labels Dec 7, 2022
@github-actions github-actions bot added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Dec 7, 2022
@melloware melloware changed the title Component: FileUpload - PrimeReact 8.6.1 FileUpload: Control internal files state Dec 7, 2022
@melloware
Copy link
Member

@harsha16208 can you give your exact example of what files are allowed ".png, .jpg" I don't see how ".txt" is getting in there if you are saying its not a valid format?

also I think I can just expose a setFiles method on the Ref to solve this issue?

melloware added a commit to melloware/primereact that referenced this issue Dec 7, 2022
@melloware melloware removed Status: Discussion Issue or pull request needs to be discussed by Core Team Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Dec 7, 2022
@melloware melloware added this to the 8.7.4 milestone Dec 7, 2022
@melloware melloware self-assigned this Dec 7, 2022
@melloware
Copy link
Member

I added a new method on the ref public setFiles(files: File[]): void;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: New Feature Issue contains a new feature or new component request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants