Skip to content

Commit

Permalink
Created maxFile validator (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashlook committed May 3, 2020
1 parent 5a51c53 commit 0e5bd48
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@ import { ValidatorFn, FormControl } from '@angular/forms';

export class FileValidators {

/**
* Function to control the total number of files max
* @param maxFile max number of files
*/
static maxFile(maxFiles: number): ValidatorFn {
const fn = (control: FormControl): { [key: string]: any } | null => {
const files: FileList = control.value;
if (!files || files.length <= 0) {
return null;
}
if (files.length > maxFiles) {
return {
maxFile: {
maxFiles,
currentFiles: files.length,
}
};
}
return null;
};
return fn;
}

/**
* Function to control the total max size of the files
* @param maxSize The total max size
Expand Down

0 comments on commit 0e5bd48

Please sign in to comment.