]>
Commit | Line | Data |
---|---|---|
7ed1edbb C |
1 | import { Validators, AbstractControl } from '@angular/forms' |
2 | import { BuildFormValidator } from './form-validator.model' | |
3 | import { VideoPlaylistPrivacy } from '@shared/models' | |
4 | ||
5 | export const VIDEO_PLAYLIST_DISPLAY_NAME_VALIDATOR: BuildFormValidator = { | |
6 | VALIDATORS: [ | |
7 | Validators.required, | |
8 | Validators.minLength(1), | |
9 | Validators.maxLength(120) | |
10 | ], | |
11 | MESSAGES: { | |
12 | 'required': $localize`Display name is required.`, | |
13 | 'minlength': $localize`Display name must be at least 1 character long.`, | |
14 | 'maxlength': $localize`Display name cannot be more than 120 characters long.` | |
15 | } | |
16 | } | |
17 | ||
18 | export const VIDEO_PLAYLIST_PRIVACY_VALIDATOR: BuildFormValidator = { | |
19 | VALIDATORS: [ | |
20 | Validators.required | |
21 | ], | |
22 | MESSAGES: { | |
23 | 'required': $localize`Privacy is required.` | |
24 | } | |
25 | } | |
26 | ||
27 | export const VIDEO_PLAYLIST_DESCRIPTION_VALIDATOR: BuildFormValidator = { | |
28 | VALIDATORS: [ | |
29 | Validators.minLength(3), | |
30 | Validators.maxLength(1000) | |
31 | ], | |
32 | MESSAGES: { | |
33 | 'minlength': $localize`Description must be at least 3 characters long.`, | |
34 | 'maxlength': $localize`Description cannot be more than 1000 characters long.` | |
35 | } | |
36 | } | |
37 | ||
38 | export const VIDEO_PLAYLIST_CHANNEL_ID_VALIDATOR: BuildFormValidator = { | |
39 | VALIDATORS: [], | |
40 | MESSAGES: { | |
41 | 'required': $localize`The channel is required when the playlist is public.` | |
42 | } | |
43 | } | |
44 | ||
45 | export function setPlaylistChannelValidator (channelControl: AbstractControl, privacy: VideoPlaylistPrivacy) { | |
46 | if (privacy.toString() === VideoPlaylistPrivacy.PUBLIC.toString()) { | |
47 | channelControl.setValidators([Validators.required]) | |
48 | } else { | |
49 | channelControl.setValidators(null) | |
50 | } | |
51 | ||
52 | channelControl.markAsDirty() | |
53 | channelControl.updateValueAndValidity() | |
54 | } |