From b58a894bc9cb0c02fb61efd00415dcf433b83567 Mon Sep 17 00:00:00 2001 From: Ramiellll Date: Tue, 23 Feb 2021 22:16:35 +0100 Subject: Fix titles do not trim leading and trailing spaces --- .../src/app/shared/form-validators/video-validators.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'client/src/app') 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 @@ -import { AbstractControl, ValidationErrors, ValidatorFn, Validators } from '@angular/forms' +import { AbstractControl, ValidationErrors, ValidatorFn, Validators, FormControl } from '@angular/forms' import { BuildFormValidator } from './form-validator.model' +export const trimValidator: ValidatorFn = (control: FormControl) => { + if (control.value.startsWith(' ') || control.value.endsWith(' ')) { + return { + 'spaces': true + } + } + return null; +}; + export const VIDEO_NAME_VALIDATOR: BuildFormValidator = { - VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(120) ], + VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(120), trimValidator ], MESSAGES: { 'required': $localize`Video name is required.`, 'minlength': $localize`Video name must be at least 3 characters long.`, - 'maxlength': $localize`Video name cannot be more than 120 characters long.` + 'maxlength': $localize`Video name cannot be more than 120 characters long.`, + 'spaces': $localize`Video name has leading or trailing whitespace.` } } -- cgit v1.2.3