ngx-dropzone
ngx-dropzone copied to clipboard
Feature: validate maxSize of all files
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 } }
}
}
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.