1 import { AbstractControl, ValidationErrors, ValidatorFn, Validators } from '@angular/forms'
2 import { BuildFormValidator } from './form-validator.model'
4 export const VIDEO_NAME_VALIDATOR: BuildFormValidator = {
5 VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(120) ],
7 'required': $localize`Video name is required.`,
8 'minlength': $localize`Video name must be at least 3 characters long.`,
9 'maxlength': $localize`Video name cannot be more than 120 characters long.`
13 export const VIDEO_PRIVACY_VALIDATOR: BuildFormValidator = {
14 VALIDATORS: [ Validators.required ],
16 'required': $localize`Video privacy is required.`
20 export const VIDEO_CATEGORY_VALIDATOR: BuildFormValidator = {
25 export const VIDEO_LICENCE_VALIDATOR: BuildFormValidator = {
30 export const VIDEO_LANGUAGE_VALIDATOR: BuildFormValidator = {
35 export const VIDEO_IMAGE_VALIDATOR: BuildFormValidator = {
40 export const VIDEO_CHANNEL_VALIDATOR: BuildFormValidator = {
41 VALIDATORS: [ Validators.required ],
43 'required': $localize`Video channel is required.`
47 export const VIDEO_DESCRIPTION_VALIDATOR: BuildFormValidator = {
48 VALIDATORS: [ Validators.minLength(3), Validators.maxLength(10000) ],
50 'minlength': $localize`Video description must be at least 3 characters long.`,
51 'maxlength': $localize`Video description cannot be more than 10000 characters long.`
55 export const VIDEO_TAG_VALIDATOR: BuildFormValidator = {
56 VALIDATORS: [ Validators.minLength(2), Validators.maxLength(30) ],
58 'minlength': $localize`A tag should be more than 2 characters long.`,
59 'maxlength': $localize`A tag should be less than 30 characters long.`
63 export const VIDEO_TAGS_ARRAY_VALIDATOR: BuildFormValidator = {
64 VALIDATORS: [ Validators.maxLength(5), arrayTagLengthValidator() ],
66 'maxlength': $localize`A maximum of 5 tags can be used on a video.`,
67 'arrayTagLength': $localize`A tag should be more than 1 and less than 30 characters long.`
71 export const VIDEO_SUPPORT_VALIDATOR: BuildFormValidator = {
72 VALIDATORS: [ Validators.minLength(3), Validators.maxLength(1000) ],
74 'minlength': $localize`Video support must be at least 3 characters long.`,
75 'maxlength': $localize`Video support cannot be more than 1000 characters long.`
79 export const VIDEO_SCHEDULE_PUBLICATION_AT_VALIDATOR: BuildFormValidator = {
82 'required': $localize`A date is required to schedule video update.`
86 export const VIDEO_ORIGINALLY_PUBLISHED_AT_VALIDATOR: BuildFormValidator = {
91 function arrayTagLengthValidator (min = 2, max = 30): ValidatorFn {
92 return (control: AbstractControl): ValidationErrors => {
93 const array = control.value as Array<string>
95 if (array.every(e => e.length >= min && e.length <= max)) {
99 return { 'arrayTagLength': true }