diff options
author | Ramiellll <ramyyy.ramiel@gmail.com> | 2021-02-23 22:16:35 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2021-02-25 09:55:34 +0100 |
commit | b58a894bc9cb0c02fb61efd00415dcf433b83567 (patch) | |
tree | 41fca554277f61517eb27406c1e2fb951a240ca3 /client/src/app/shared | |
parent | e072fb1e1633e57c986b2d19646b7a140af03bb8 (diff) | |
download | PeerTube-b58a894bc9cb0c02fb61efd00415dcf433b83567.tar.gz PeerTube-b58a894bc9cb0c02fb61efd00415dcf433b83567.tar.zst PeerTube-b58a894bc9cb0c02fb61efd00415dcf433b83567.zip |
Fix titles do not trim leading and trailing spaces
Diffstat (limited to 'client/src/app/shared')
-rw-r--r-- | client/src/app/shared/form-validators/video-validators.ts | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/client/src/app/shared/form-validators/video-validators.ts b/client/src/app/shared/form-validators/video-validators.ts index b3ce876b1..0000f18ba 100644 --- a/client/src/app/shared/form-validators/video-validators.ts +++ b/client/src/app/shared/form-validators/video-validators.ts | |||
@@ -1,12 +1,22 @@ | |||
1 | import { AbstractControl, ValidationErrors, ValidatorFn, Validators } from '@angular/forms' | 1 | import { AbstractControl, ValidationErrors, ValidatorFn, Validators, FormControl } from '@angular/forms' |
2 | import { BuildFormValidator } from './form-validator.model' | 2 | import { BuildFormValidator } from './form-validator.model' |
3 | 3 | ||
4 | export const trimValidator: ValidatorFn = (control: FormControl) => { | ||
5 | if (control.value.startsWith(' ') || control.value.endsWith(' ')) { | ||
6 | return { | ||
7 | 'spaces': true | ||
8 | } | ||
9 | } | ||
10 | return null; | ||
11 | }; | ||
12 | |||
4 | export const VIDEO_NAME_VALIDATOR: BuildFormValidator = { | 13 | export const VIDEO_NAME_VALIDATOR: BuildFormValidator = { |
5 | VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(120) ], | 14 | VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(120), trimValidator ], |
6 | MESSAGES: { | 15 | MESSAGES: { |
7 | 'required': $localize`Video name is required.`, | 16 | 'required': $localize`Video name is required.`, |
8 | 'minlength': $localize`Video name must be at least 3 characters long.`, | 17 | 'minlength': $localize`Video name must be at least 3 characters long.`, |
9 | 'maxlength': $localize`Video name cannot be more than 120 characters long.` | 18 | 'maxlength': $localize`Video name cannot be more than 120 characters long.`, |
19 | 'spaces': $localize`Video name has leading or trailing whitespace.` | ||
10 | } | 20 | } |
11 | } | 21 | } |
12 | 22 | ||