diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-08-05 00:50:07 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-08-11 09:03:39 +0200 |
commit | 02c01341f4dae30ec6b81fcb644952393d73c4a8 (patch) | |
tree | aca3f2b118bb123457fd38724be68fe877504c75 /client/src/app/shared/shared-forms/form-validators | |
parent | 766d13b4470de02d3d7bec94188260b89a356399 (diff) | |
download | PeerTube-02c01341f4dae30ec6b81fcb644952393d73c4a8.tar.gz PeerTube-02c01341f4dae30ec6b81fcb644952393d73c4a8.tar.zst PeerTube-02c01341f4dae30ec6b81fcb644952393d73c4a8.zip |
add ng-select for templatable select options
- create select-tags component to replace ngx-chips
- create select-options to factorize option selection in forms
- create select-channel to simplify channel selection
- refactor tags validation
Diffstat (limited to 'client/src/app/shared/shared-forms/form-validators')
-rw-r--r-- | client/src/app/shared/shared-forms/form-validators/video-validators.service.ts | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/client/src/app/shared/shared-forms/form-validators/video-validators.service.ts b/client/src/app/shared/shared-forms/form-validators/video-validators.service.ts index 9b24e4f62..c96e4ef66 100644 --- a/client/src/app/shared/shared-forms/form-validators/video-validators.service.ts +++ b/client/src/app/shared/shared-forms/form-validators/video-validators.service.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { I18n } from '@ngx-translate/i18n-polyfill' | 1 | import { I18n } from '@ngx-translate/i18n-polyfill' |
2 | import { Validators } from '@angular/forms' | 2 | import { Validators, ValidatorFn, ValidationErrors, AbstractControl } from '@angular/forms' |
3 | import { Injectable } from '@angular/core' | 3 | import { Injectable } from '@angular/core' |
4 | import { BuildFormValidator } from './form-validator.service' | 4 | import { BuildFormValidator } from './form-validator.service' |
5 | 5 | ||
@@ -13,7 +13,8 @@ export class VideoValidatorsService { | |||
13 | readonly VIDEO_IMAGE: BuildFormValidator | 13 | readonly VIDEO_IMAGE: BuildFormValidator |
14 | readonly VIDEO_CHANNEL: BuildFormValidator | 14 | readonly VIDEO_CHANNEL: BuildFormValidator |
15 | readonly VIDEO_DESCRIPTION: BuildFormValidator | 15 | readonly VIDEO_DESCRIPTION: BuildFormValidator |
16 | readonly VIDEO_TAGS: BuildFormValidator | 16 | readonly VIDEO_TAGS_ARRAY: BuildFormValidator |
17 | readonly VIDEO_TAG: BuildFormValidator | ||
17 | readonly VIDEO_SUPPORT: BuildFormValidator | 18 | readonly VIDEO_SUPPORT: BuildFormValidator |
18 | readonly VIDEO_SCHEDULE_PUBLICATION_AT: BuildFormValidator | 19 | readonly VIDEO_SCHEDULE_PUBLICATION_AT: BuildFormValidator |
19 | readonly VIDEO_ORIGINALLY_PUBLISHED_AT: BuildFormValidator | 20 | readonly VIDEO_ORIGINALLY_PUBLISHED_AT: BuildFormValidator |
@@ -71,7 +72,7 @@ export class VideoValidatorsService { | |||
71 | } | 72 | } |
72 | } | 73 | } |
73 | 74 | ||
74 | this.VIDEO_TAGS = { | 75 | this.VIDEO_TAG = { |
75 | VALIDATORS: [ Validators.minLength(2), Validators.maxLength(30) ], | 76 | VALIDATORS: [ Validators.minLength(2), Validators.maxLength(30) ], |
76 | MESSAGES: { | 77 | MESSAGES: { |
77 | 'minlength': this.i18n('A tag should be more than 2 characters long.'), | 78 | 'minlength': this.i18n('A tag should be more than 2 characters long.'), |
@@ -79,6 +80,14 @@ export class VideoValidatorsService { | |||
79 | } | 80 | } |
80 | } | 81 | } |
81 | 82 | ||
83 | this.VIDEO_TAGS_ARRAY = { | ||
84 | VALIDATORS: [ Validators.maxLength(5), this.arrayTagLengthValidator() ], | ||
85 | MESSAGES: { | ||
86 | 'maxlength': this.i18n('A maximum of 5 tags can be used on a video.'), | ||
87 | 'arrayTagLength': this.i18n('A tag should be more than 2, and less than 30 characters long.') | ||
88 | } | ||
89 | } | ||
90 | |||
82 | this.VIDEO_SUPPORT = { | 91 | this.VIDEO_SUPPORT = { |
83 | VALIDATORS: [ Validators.minLength(3), Validators.maxLength(1000) ], | 92 | VALIDATORS: [ Validators.minLength(3), Validators.maxLength(1000) ], |
84 | MESSAGES: { | 93 | MESSAGES: { |
@@ -99,4 +108,16 @@ export class VideoValidatorsService { | |||
99 | MESSAGES: {} | 108 | MESSAGES: {} |
100 | } | 109 | } |
101 | } | 110 | } |
111 | |||
112 | arrayTagLengthValidator (min = 2, max = 30): ValidatorFn { | ||
113 | return (control: AbstractControl): ValidationErrors => { | ||
114 | const array = control.value as Array<string> | ||
115 | |||
116 | if (array.every(e => e.length > min && e.length < max)) { | ||
117 | return null | ||
118 | } | ||
119 | |||
120 | return { 'arrayTagLength': true } | ||
121 | } | ||
122 | } | ||
102 | } | 123 | } |