aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/forms
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared/forms')
-rw-r--r--client/src/app/shared/forms/form-reactive.ts30
-rw-r--r--client/src/app/shared/forms/form-validators/host.validator.ts8
-rw-r--r--client/src/app/shared/forms/form-validators/index.ts8
-rw-r--r--client/src/app/shared/forms/form-validators/user.ts12
-rw-r--r--client/src/app/shared/forms/form-validators/video-abuse.ts4
-rw-r--r--client/src/app/shared/forms/form-validators/video.ts14
-rw-r--r--client/src/app/shared/forms/index.ts4
7 files changed, 40 insertions, 40 deletions
diff --git a/client/src/app/shared/forms/form-reactive.ts b/client/src/app/shared/forms/form-reactive.ts
index a5732e083..e7764d069 100644
--- a/client/src/app/shared/forms/form-reactive.ts
+++ b/client/src/app/shared/forms/form-reactive.ts
@@ -1,38 +1,38 @@
1import { FormGroup } from '@angular/forms'; 1import { FormGroup } from '@angular/forms'
2 2
3export abstract class FormReactive { 3export abstract class FormReactive {
4 abstract form: FormGroup; 4 abstract form: FormGroup
5 abstract formErrors: Object; 5 abstract formErrors: Object
6 abstract validationMessages: Object; 6 abstract validationMessages: Object
7 7
8 abstract buildForm(): void; 8 abstract buildForm (): void
9 9
10 protected onValueChanged(data?: any) { 10 protected onValueChanged (data?: any) {
11 for (const field in this.formErrors) { 11 for (const field in this.formErrors) {
12 // clear previous error message (if any) 12 // clear previous error message (if any)
13 this.formErrors[field] = ''; 13 this.formErrors[field] = ''
14 const control = this.form.get(field); 14 const control = this.form.get(field)
15 15
16 if (control && control.dirty && !control.valid) { 16 if (control && control.dirty && !control.valid) {
17 const messages = this.validationMessages[field]; 17 const messages = this.validationMessages[field]
18 for (const key in control.errors) { 18 for (const key in control.errors) {
19 this.formErrors[field] += messages[key] + ' '; 19 this.formErrors[field] += messages[key] + ' '
20 } 20 }
21 } 21 }
22 } 22 }
23 } 23 }
24 24
25 // Same as onValueChanged but force checking even if the field is not dirty 25 // Same as onValueChanged but force checking even if the field is not dirty
26 protected forceCheck() { 26 protected forceCheck () {
27 for (const field in this.formErrors) { 27 for (const field in this.formErrors) {
28 // clear previous error message (if any) 28 // clear previous error message (if any)
29 this.formErrors[field] = ''; 29 this.formErrors[field] = ''
30 const control = this.form.get(field); 30 const control = this.form.get(field)
31 31
32 if (control && !control.valid) { 32 if (control && !control.valid) {
33 const messages = this.validationMessages[field]; 33 const messages = this.validationMessages[field]
34 for (const key in control.errors) { 34 for (const key in control.errors) {
35 this.formErrors[field] += messages[key] + ' '; 35 this.formErrors[field] += messages[key] + ' '
36 } 36 }
37 } 37 }
38 } 38 }
diff --git a/client/src/app/shared/forms/form-validators/host.validator.ts b/client/src/app/shared/forms/form-validators/host.validator.ts
index ec417e079..03e810fdb 100644
--- a/client/src/app/shared/forms/form-validators/host.validator.ts
+++ b/client/src/app/shared/forms/form-validators/host.validator.ts
@@ -1,14 +1,14 @@
1import { FormControl } from '@angular/forms'; 1import { FormControl } from '@angular/forms'
2 2
3export function validateHost(c: FormControl) { 3export function validateHost (c: FormControl) {
4 // Thanks to http://stackoverflow.com/a/106223 4 // Thanks to http://stackoverflow.com/a/106223
5 const HOST_REGEXP = new RegExp( 5 const HOST_REGEXP = new RegExp(
6 '^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$' 6 '^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$'
7 ); 7 )
8 8
9 return HOST_REGEXP.test(c.value) ? null : { 9 return HOST_REGEXP.test(c.value) ? null : {
10 validateHost: { 10 validateHost: {
11 valid: false 11 valid: false
12 } 12 }
13 }; 13 }
14} 14}
diff --git a/client/src/app/shared/forms/form-validators/index.ts b/client/src/app/shared/forms/form-validators/index.ts
index ab7c2df31..efe77d4ae 100644
--- a/client/src/app/shared/forms/form-validators/index.ts
+++ b/client/src/app/shared/forms/form-validators/index.ts
@@ -1,4 +1,4 @@
1export * from './host.validator'; 1export * from './host.validator'
2export * from './user'; 2export * from './user'
3export * from './video-abuse'; 3export * from './video-abuse'
4export * from './video'; 4export * from './video'
diff --git a/client/src/app/shared/forms/form-validators/user.ts b/client/src/app/shared/forms/form-validators/user.ts
index 259d2b868..fd316583e 100644
--- a/client/src/app/shared/forms/form-validators/user.ts
+++ b/client/src/app/shared/forms/form-validators/user.ts
@@ -1,4 +1,4 @@
1import { Validators } from '@angular/forms'; 1import { Validators } from '@angular/forms'
2 2
3export const USER_USERNAME = { 3export const USER_USERNAME = {
4 VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(20) ], 4 VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(20) ],
@@ -7,18 +7,18 @@ export const USER_USERNAME = {
7 'minlength': 'Username must be at least 3 characters long.', 7 'minlength': 'Username must be at least 3 characters long.',
8 'maxlength': 'Username cannot be more than 20 characters long.' 8 'maxlength': 'Username cannot be more than 20 characters long.'
9 } 9 }
10}; 10}
11export const USER_EMAIL = { 11export const USER_EMAIL = {
12 VALIDATORS: [ Validators.required, Validators.email ], 12 VALIDATORS: [ Validators.required, Validators.email ],
13 MESSAGES: { 13 MESSAGES: {
14 'required': 'Email is required.', 14 'required': 'Email is required.',
15 'email': 'Email must be valid.', 15 'email': 'Email must be valid.'
16 } 16 }
17}; 17}
18export const USER_PASSWORD = { 18export const USER_PASSWORD = {
19 VALIDATORS: [ Validators.required, Validators.minLength(6) ], 19 VALIDATORS: [ Validators.required, Validators.minLength(6) ],
20 MESSAGES: { 20 MESSAGES: {
21 'required': 'Password is required.', 21 'required': 'Password is required.',
22 'minlength': 'Password must be at least 6 characters long.', 22 'minlength': 'Password must be at least 6 characters long.'
23 } 23 }
24}; 24}
diff --git a/client/src/app/shared/forms/form-validators/video-abuse.ts b/client/src/app/shared/forms/form-validators/video-abuse.ts
index 94a29a3b7..3c7f26205 100644
--- a/client/src/app/shared/forms/form-validators/video-abuse.ts
+++ b/client/src/app/shared/forms/form-validators/video-abuse.ts
@@ -1,4 +1,4 @@
1import { Validators } from '@angular/forms'; 1import { Validators } from '@angular/forms'
2 2
3export const VIDEO_ABUSE_REASON = { 3export const VIDEO_ABUSE_REASON = {
4 VALIDATORS: [ Validators.required, Validators.minLength(2), Validators.maxLength(300) ], 4 VALIDATORS: [ Validators.required, Validators.minLength(2), Validators.maxLength(300) ],
@@ -7,4 +7,4 @@ export const VIDEO_ABUSE_REASON = {
7 'minlength': 'Report reson must be at least 2 characters long.', 7 'minlength': 'Report reson must be at least 2 characters long.',
8 'maxlength': 'Report reson cannot be more than 300 characters long.' 8 'maxlength': 'Report reson cannot be more than 300 characters long.'
9 } 9 }
10}; 10}
diff --git a/client/src/app/shared/forms/form-validators/video.ts b/client/src/app/shared/forms/form-validators/video.ts
index f7e4e5e4b..6542cf8f6 100644
--- a/client/src/app/shared/forms/form-validators/video.ts
+++ b/client/src/app/shared/forms/form-validators/video.ts
@@ -1,4 +1,4 @@
1import { Validators } from '@angular/forms'; 1import { Validators } from '@angular/forms'
2 2
3export const VIDEO_NAME = { 3export const VIDEO_NAME = {
4 VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(50) ], 4 VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(50) ],
@@ -7,26 +7,26 @@ export const VIDEO_NAME = {
7 'minlength': 'Video name must be at least 3 characters long.', 7 'minlength': 'Video name must be at least 3 characters long.',
8 'maxlength': 'Video name cannot be more than 50 characters long.' 8 'maxlength': 'Video name cannot be more than 50 characters long.'
9 } 9 }
10}; 10}
11 11
12export const VIDEO_CATEGORY = { 12export const VIDEO_CATEGORY = {
13 VALIDATORS: [ Validators.required ], 13 VALIDATORS: [ Validators.required ],
14 MESSAGES: { 14 MESSAGES: {
15 'required': 'Video category is required.' 15 'required': 'Video category is required.'
16 } 16 }
17}; 17}
18 18
19export const VIDEO_LICENCE = { 19export const VIDEO_LICENCE = {
20 VALIDATORS: [ Validators.required ], 20 VALIDATORS: [ Validators.required ],
21 MESSAGES: { 21 MESSAGES: {
22 'required': 'Video licence is required.' 22 'required': 'Video licence is required.'
23 } 23 }
24}; 24}
25 25
26export const VIDEO_LANGUAGE = { 26export const VIDEO_LANGUAGE = {
27 VALIDATORS: [ ], 27 VALIDATORS: [ ],
28 MESSAGES: {} 28 MESSAGES: {}
29}; 29}
30 30
31export const VIDEO_DESCRIPTION = { 31export const VIDEO_DESCRIPTION = {
32 VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(250) ], 32 VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(250) ],
@@ -35,7 +35,7 @@ export const VIDEO_DESCRIPTION = {
35 'minlength': 'Video description must be at least 3 characters long.', 35 'minlength': 'Video description must be at least 3 characters long.',
36 'maxlength': 'Video description cannot be more than 250 characters long.' 36 'maxlength': 'Video description cannot be more than 250 characters long.'
37 } 37 }
38}; 38}
39 39
40export const VIDEO_TAGS = { 40export const VIDEO_TAGS = {
41 VALIDATORS: [ Validators.minLength(2), Validators.maxLength(10) ], 41 VALIDATORS: [ Validators.minLength(2), Validators.maxLength(10) ],
@@ -43,4 +43,4 @@ export const VIDEO_TAGS = {
43 'minlength': 'A tag should be more than 2 characters long.', 43 'minlength': 'A tag should be more than 2 characters long.',
44 'maxlength': 'A tag should be less than 10 characters long.' 44 'maxlength': 'A tag should be less than 10 characters long.'
45 } 45 }
46}; 46}
diff --git a/client/src/app/shared/forms/index.ts b/client/src/app/shared/forms/index.ts
index 588ebb4be..7464bb022 100644
--- a/client/src/app/shared/forms/index.ts
+++ b/client/src/app/shared/forms/index.ts
@@ -1,2 +1,2 @@
1export * from './form-validators'; 1export * from './form-validators'
2export * from './form-reactive'; 2export * from './form-reactive'