Skip to content

Commit

Permalink
Merge pull request #14797 from burhanrepos/filelimit-fix
Browse files Browse the repository at this point in the history
Fixed #14783 two validations simultaneously on fileupload (File limit and max file size)
  • Loading branch information
cetincakiroglu committed Feb 23, 2024
2 parents 377a584 + 0d48869 commit e333bf5
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/app/components/fileupload/fileupload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,11 +557,10 @@ export class FileUpload implements AfterViewInit, AfterContentInit, OnInit, OnDe

this.onSelect.emit({ originalEvent: event, files: files, currentFiles: this.files });

if (this.fileLimit) {
this.checkFileLimit();
}
// this will check the fileLimit with the uploaded files
this.checkFileLimit(files);

if (this.hasFiles() && this.auto && (!(this.mode === 'advanced') || !this.isFileLimitExceeded())) {
if (this.hasFiles() && this.auto && !(this.mode === 'advanced') && !this.isFileLimitExceeded()) {
this.upload();
}

Expand Down Expand Up @@ -739,7 +738,7 @@ export class FileUpload implements AfterViewInit, AfterContentInit, OnInit, OnDe
this.clearInputElement();
this.onRemove.emit({ originalEvent: event, file: this.files[index] });
this.files.splice(index, 1);
this.checkFileLimit();
this.checkFileLimit(this.files);
}

isFileLimitExceeded() {
Expand All @@ -761,9 +760,10 @@ export class FileUpload implements AfterViewInit, AfterContentInit, OnInit, OnDe
}
}

checkFileLimit() {
checkFileLimit(files: File[]) {
this.msgs ??= [];
if (this.isFileLimitExceeded()) {
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 as number).toString()),
Expand Down

0 comments on commit e333bf5

Please sign in to comment.