ngx-dropzone icon indicating copy to clipboard operation
ngx-dropzone copied to clipboard

Feature: validate maxSize of all files

Open BeniFreitag opened this issue 1 year ago • 1 comments

Please add a validator for the max file size of all files. This sample would work:

/**
 * Checks if the file size of all files is equal or smaller than the allowed size.
 * Validates every file within array. Returns no error when null.
 */
static maxSizeAllFiles(max: number): ValidatorFn {
  return (control: AbstractControl<File[]>): ValidationErrors | null => {
    const totalFileSize = control.value.reduce((partialSum, a) => partialSum + a.size, 0)
    const valid = totalFileSize <= max
    return valid ? null : { maxSizeAllFiles: { value: control.value, max } }
  }
}

BeniFreitag avatar Sep 26 '24 07:09 BeniFreitag

Hey there,

thanks for your contribution.

You are free to add any custom validators to your implementation as described in the readme. For now, I want to keep the library as small as possible and in my opinion this is not something we need in the lib necessarily.

I will leave the issue open and see if it gets some upvotes.

hackingharold avatar Sep 26 '24 19:09 hackingharold