diff options
Diffstat (limited to 'client/src/app/shared/form-validators')
-rw-r--r-- | client/src/app/shared/form-validators/video-chapter-validators.ts | 32 | ||||
-rw-r--r-- | client/src/app/shared/form-validators/video-validators.ts | 8 |
2 files changed, 32 insertions, 8 deletions
diff --git a/client/src/app/shared/form-validators/video-chapter-validators.ts b/client/src/app/shared/form-validators/video-chapter-validators.ts new file mode 100644 index 000000000..cbbd9291e --- /dev/null +++ b/client/src/app/shared/form-validators/video-chapter-validators.ts | |||
@@ -0,0 +1,32 @@ | |||
1 | import { AbstractControl, ValidationErrors, ValidatorFn, Validators } from '@angular/forms' | ||
2 | import { BuildFormValidator } from './form-validator.model' | ||
3 | |||
4 | export const VIDEO_CHAPTER_TITLE_VALIDATOR: BuildFormValidator = { | ||
5 | VALIDATORS: [ Validators.minLength(2), Validators.maxLength(100) ], // Required is set dynamically | ||
6 | MESSAGES: { | ||
7 | required: $localize`A chapter title is required.`, | ||
8 | minlength: $localize`A chapter title should be more than 2 characters long.`, | ||
9 | maxlength: $localize`A chapter title should be less than 100 characters long.` | ||
10 | } | ||
11 | } | ||
12 | |||
13 | export const VIDEO_CHAPTERS_ARRAY_VALIDATOR: BuildFormValidator = { | ||
14 | VALIDATORS: [ uniqueTimecodeValidator() ], | ||
15 | MESSAGES: {} | ||
16 | } | ||
17 | |||
18 | function uniqueTimecodeValidator (): ValidatorFn { | ||
19 | return (control: AbstractControl): ValidationErrors => { | ||
20 | const array = control.value as { timecode: number, title: string }[] | ||
21 | |||
22 | for (const chapter of array) { | ||
23 | if (!chapter.title) continue | ||
24 | |||
25 | if (array.filter(c => c.title && c.timecode === chapter.timecode).length > 1) { | ||
26 | return { uniqueTimecode: $localize`Multiple chapters have the same timecode ${chapter.timecode}` } | ||
27 | } | ||
28 | } | ||
29 | |||
30 | return null | ||
31 | } | ||
32 | } | ||
diff --git a/client/src/app/shared/form-validators/video-validators.ts b/client/src/app/shared/form-validators/video-validators.ts index 090a76e43..a434c777f 100644 --- a/client/src/app/shared/form-validators/video-validators.ts +++ b/client/src/app/shared/form-validators/video-validators.ts | |||
@@ -70,14 +70,6 @@ export const VIDEO_DESCRIPTION_VALIDATOR: BuildFormValidator = { | |||
70 | } | 70 | } |
71 | } | 71 | } |
72 | 72 | ||
73 | export const VIDEO_TAG_VALIDATOR: BuildFormValidator = { | ||
74 | VALIDATORS: [ Validators.minLength(2), Validators.maxLength(30) ], | ||
75 | MESSAGES: { | ||
76 | minlength: $localize`A tag should be more than 2 characters long.`, | ||
77 | maxlength: $localize`A tag should be less than 30 characters long.` | ||
78 | } | ||
79 | } | ||
80 | |||
81 | export const VIDEO_TAGS_ARRAY_VALIDATOR: BuildFormValidator = { | 73 | export const VIDEO_TAGS_ARRAY_VALIDATOR: BuildFormValidator = { |
82 | VALIDATORS: [ Validators.maxLength(5), arrayTagLengthValidator() ], | 74 | VALIDATORS: [ Validators.maxLength(5), arrayTagLengthValidator() ], |
83 | MESSAGES: { | 75 | MESSAGES: { |