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

p-fileUpload selecting file when fileLimit set to undefined causes js errors #15988

Closed
majkers opened this issue Jul 9, 2024 · 2 comments
Closed
Labels
Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible

Comments

@majkers
Copy link

majkers commented Jul 9, 2024

I have a component build on top of fileUpload but with signal inputs. Filelimit property is done like this:
fileLimit: InputSignal<number | undefined> = input<number | undefined>();
and when I don't set it in my component, it passes undefined to primeNg. Then transform does his job and value of fileLimit inside primeNg has null as value:
@Input({ transform: (value: unknown) => numberAttribute(value, null) }) fileLimit: number | undefined;
Then when trying to select file to upload with fileSize limit this functuion is being called:

  checkFileLimit(files) {
    this.msgs ??= [];
    const hasExistingValidationMessages = this.msgs.length > 0 && this.fileLimit < files.length;
    if (this.isFileLimitExceeded() || hasExistingValidationMessages) {
      this.msgs.push({
        severity: 'error',
        summary: this.invalidFileLimitMessageSummary.replace('{0}', this.fileLimit.toString()),
        detail: this.invalidFileLimitMessageDetail.replace('{0}', this.fileLimit.toString())
      });
    }
  }

And when fileLimit is null, this
const hasExistingValidationMessages = this.msgs.length > 0 && this.fileLimit < files.length;
is true and I get error in my js console:

core.mjs:6531 ERROR TypeError: Cannot read properties of null (reading 'toString')
    at _FileUpload.checkFileLimit (primeng-fileupload.mjs:1312:84)
    at _FileUpload.onFileSelect (primeng-fileupload.mjs:1106:10)

IMHO. What is missing in hasExistingValidationMessages is checking this part:
this.fileLimit
like this:
const hasExistingValidationMessages = this.msgs.length > 0 && this.fileLimit && this.fileLimit < files.length;
or transform should be fixed.

Environment

primeNG 17.8.3

Reproducer

No response

Angular version

17.3.11

PrimeNG version

17.8.3

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

20.12.2

Browser(s)

All

Steps to reproduce the behavior

No response

Expected behavior

No js errors in console

@majkers majkers added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Jul 9, 2024
@gregorwinkler
Copy link

gregorwinkler commented Jul 16, 2024

I can reproduce the problem and have it as well in my project.

I'm not entirely sure why the following is needed in the first place:
const hasExistingValidationMessages = this.msgs.length > 0 && this.fileLimit < files.length; (fileupload.ts:856)

Why is it not sufficient to check just for this.isFileLimitExceeded() instead of (this.isFileLimitExceeded() || hasExistingValidationMessages)?

@mertsincan
Copy link
Member

Hi,

So sorry for the delayed response! Improvements have been made to many components recently, both in terms of performance and enhancement. Therefore, this improvement may have been developed in another issue ticket without realizing it. You can check this in the documentation. If there is no improvement on this, can you open a new issue so we can include it in our roadmap?

Thanks a lot for your understanding!
Best Regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible
Projects
None yet
Development

No branches or pull requests

3 participants