1 import { Validators, AbstractControl } from '@angular/forms'
2 import { BuildFormValidator } from './form-validator.model'
3 import { VideoPlaylistPrivacy } from '@shared/models'
5 export const VIDEO_PLAYLIST_DISPLAY_NAME_VALIDATOR: BuildFormValidator = {
8 Validators.minLength(1),
9 Validators.maxLength(120)
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.`
18 export const VIDEO_PLAYLIST_PRIVACY_VALIDATOR: BuildFormValidator = {
23 'required': $localize`Privacy is required.`
27 export const VIDEO_PLAYLIST_DESCRIPTION_VALIDATOR: BuildFormValidator = {
29 Validators.minLength(3),
30 Validators.maxLength(1000)
33 'minlength': $localize`Description must be at least 3 characters long.`,
34 'maxlength': $localize`Description cannot be more than 1000 characters long.`
38 export const VIDEO_PLAYLIST_CHANNEL_ID_VALIDATOR: BuildFormValidator = {
41 'required': $localize`The channel is required when the playlist is public.`
45 export function setPlaylistChannelValidator (channelControl: AbstractControl, privacy: VideoPlaylistPrivacy) {
46 if (privacy.toString() === VideoPlaylistPrivacy.PUBLIC.toString()) {
47 channelControl.setValidators([Validators.required])
49 channelControl.setValidators(null)
52 channelControl.markAsDirty()
53 channelControl.updateValueAndValidity()