From 02c01341f4dae30ec6b81fcb644952393d73c4a8 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Wed, 5 Aug 2020 00:50:07 +0200 Subject: 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 --- .../form-validators/video-validators.service.ts | 27 +++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'client/src/app/shared/shared-forms/form-validators') 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 @@ import { I18n } from '@ngx-translate/i18n-polyfill' -import { Validators } from '@angular/forms' +import { Validators, ValidatorFn, ValidationErrors, AbstractControl } from '@angular/forms' import { Injectable } from '@angular/core' import { BuildFormValidator } from './form-validator.service' @@ -13,7 +13,8 @@ export class VideoValidatorsService { readonly VIDEO_IMAGE: BuildFormValidator readonly VIDEO_CHANNEL: BuildFormValidator readonly VIDEO_DESCRIPTION: BuildFormValidator - readonly VIDEO_TAGS: BuildFormValidator + readonly VIDEO_TAGS_ARRAY: BuildFormValidator + readonly VIDEO_TAG: BuildFormValidator readonly VIDEO_SUPPORT: BuildFormValidator readonly VIDEO_SCHEDULE_PUBLICATION_AT: BuildFormValidator readonly VIDEO_ORIGINALLY_PUBLISHED_AT: BuildFormValidator @@ -71,7 +72,7 @@ export class VideoValidatorsService { } } - this.VIDEO_TAGS = { + this.VIDEO_TAG = { VALIDATORS: [ Validators.minLength(2), Validators.maxLength(30) ], MESSAGES: { 'minlength': this.i18n('A tag should be more than 2 characters long.'), @@ -79,6 +80,14 @@ export class VideoValidatorsService { } } + this.VIDEO_TAGS_ARRAY = { + VALIDATORS: [ Validators.maxLength(5), this.arrayTagLengthValidator() ], + MESSAGES: { + 'maxlength': this.i18n('A maximum of 5 tags can be used on a video.'), + 'arrayTagLength': this.i18n('A tag should be more than 2, and less than 30 characters long.') + } + } + this.VIDEO_SUPPORT = { VALIDATORS: [ Validators.minLength(3), Validators.maxLength(1000) ], MESSAGES: { @@ -99,4 +108,16 @@ export class VideoValidatorsService { MESSAGES: {} } } + + arrayTagLengthValidator (min = 2, max = 30): ValidatorFn { + return (control: AbstractControl): ValidationErrors => { + const array = control.value as Array + + if (array.every(e => e.length > min && e.length < max)) { + return null + } + + return { 'arrayTagLength': true } + } + } } -- cgit v1.2.3