aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-forms
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-12-22 18:02:36 +0100
committerChocobozzz <me@florianbigard.com>2021-12-29 10:10:01 +0100
commit3c065fe3b3e1385d59ad1980251d14b712648155 (patch)
treef5f7f1b428b8155a735014304e2d45b9ed92fe07 /client/src/app/shared/shared-forms
parent61cc1c03bf6f12af7c1b2e2a7d2fdaa563c37b59 (diff)
downloadPeerTube-3c065fe3b3e1385d59ad1980251d14b712648155.tar.gz
PeerTube-3c065fe3b3e1385d59ad1980251d14b712648155.tar.zst
PeerTube-3c065fe3b3e1385d59ad1980251d14b712648155.zip
Enhance plugin video fields
Add video form tab selection Add ability to display an error
Diffstat (limited to 'client/src/app/shared/shared-forms')
-rw-r--r--client/src/app/shared/shared-forms/form-reactive.ts19
-rw-r--r--client/src/app/shared/shared-forms/form-validator.service.ts10
2 files changed, 18 insertions, 11 deletions
diff --git a/client/src/app/shared/shared-forms/form-reactive.ts b/client/src/app/shared/shared-forms/form-reactive.ts
index f2ce82360..30b59c141 100644
--- a/client/src/app/shared/shared-forms/form-reactive.ts
+++ b/client/src/app/shared/shared-forms/form-reactive.ts
@@ -56,13 +56,18 @@ export abstract class FormReactive {
56 56
57 if (control.dirty) this.formChanged = true 57 if (control.dirty) this.formChanged = true
58 58
59 // Don't care if dirty on force check 59 if (forceCheck) control.updateValueAndValidity({ emitEvent: false })
60 const isDirty = control.dirty || forceCheck === true 60 if (!control || !control.dirty || !control.enabled || control.valid) continue
61 if (control && isDirty && control.enabled && !control.valid) { 61
62 const messages = validationMessages[field] 62 const staticMessages = validationMessages[field]
63 for (const key of Object.keys(control.errors)) { 63 for (const key of Object.keys(control.errors)) {
64 formErrors[field] += messages[key] + ' ' 64 const formErrorValue = control.errors[key]
65 } 65
66 // Try to find error message in static validation messages first
67 // Then check if the validator returns a string that is the error
68 if (typeof formErrorValue === 'boolean') formErrors[field] += staticMessages[key] + ' '
69 else if (typeof formErrorValue === 'string') formErrors[field] += control.errors[key]
70 else throw new Error('Form error value of ' + field + ' is invalid')
66 } 71 }
67 } 72 }
68 } 73 }
diff --git a/client/src/app/shared/shared-forms/form-validator.service.ts b/client/src/app/shared/shared-forms/form-validator.service.ts
index c0664de5f..055fbb2d9 100644
--- a/client/src/app/shared/shared-forms/form-validator.service.ts
+++ b/client/src/app/shared/shared-forms/form-validator.service.ts
@@ -40,7 +40,7 @@ export class FormValidatorService {
40 return { form, formErrors, validationMessages } 40 return { form, formErrors, validationMessages }
41 } 41 }
42 42
43 updateForm ( 43 updateFormGroup (
44 form: FormGroup, 44 form: FormGroup,
45 formErrors: FormReactiveErrors, 45 formErrors: FormReactiveErrors,
46 validationMessages: FormReactiveValidationMessages, 46 validationMessages: FormReactiveValidationMessages,
@@ -52,7 +52,7 @@ export class FormValidatorService {
52 52
53 const field = obj[name] 53 const field = obj[name]
54 if (this.isRecursiveField(field)) { 54 if (this.isRecursiveField(field)) {
55 this.updateForm( 55 this.updateFormGroup(
56 form[name], 56 form[name],
57 formErrors[name] as FormReactiveErrors, 57 formErrors[name] as FormReactiveErrors,
58 validationMessages[name] as FormReactiveValidationMessages, 58 validationMessages[name] as FormReactiveValidationMessages,
@@ -66,8 +66,10 @@ export class FormValidatorService {
66 66
67 const defaultValue = defaultValues[name] || '' 67 const defaultValue = defaultValues[name] || ''
68 68
69 if (field?.VALIDATORS) form.addControl(name, new FormControl(defaultValue, field.VALIDATORS as ValidatorFn[])) 69 form.addControl(
70 else form.addControl(name, new FormControl(defaultValue)) 70 name,
71 new FormControl(defaultValue, field?.VALIDATORS as ValidatorFn[])
72 )
71 } 73 }
72 } 74 }
73 75