Skip to content

Commit

Permalink
Create no-multiple-directrive (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashlook committed Apr 29, 2020
1 parent d0a54c7 commit 704d68e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { NoMultipleDirective } from './no-multiple.directive';

describe('MultipleDirective', () => {
it('should create an instance', () => {
const directive = new NoMultipleDirective();
expect(directive).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Directive } from '@angular/core';
import { NG_VALIDATORS, Validator, FormControl } from '@angular/forms';

@Directive({
selector: 'ash-mat-file-input:not([multiple])',
providers: [{ provide: NG_VALIDATORS, useExisting: NoMultipleDirective, multi: true }],
})
export class NoMultipleDirective implements Validator {

constructor() {}

validate(control: FormControl) {
if (control.value?.length > 1) {
return {
multiple: {
maxFiles: 1,
currentFiles: control.value.length,
}
};
}
return null;
}

}

0 comments on commit 704d68e

Please sign in to comment.