diff options
author | Chocobozzz <me@florianbigard.com> | 2022-09-07 16:24:44 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-09-08 08:41:48 +0200 |
commit | 8b69f9f02879ee3cf72bc9d4aa96cc71f18e6eea (patch) | |
tree | a6021e5925dae0b6da1dbb57641719357f4c3b6a | |
parent | 08d2761097f8186d2a76ff1f01391401a5a089ef (diff) | |
download | PeerTube-8b69f9f02879ee3cf72bc9d4aa96cc71f18e6eea.tar.gz PeerTube-8b69f9f02879ee3cf72bc9d4aa96cc71f18e6eea.tar.zst PeerTube-8b69f9f02879ee3cf72bc9d4aa96cc71f18e6eea.zip |
Check admin config when loading the page
Avoid issues when an invalid config was set in the configuration file
-rw-r--r-- | client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts | 6 | ||||
-rw-r--r-- | client/src/app/shared/shared-forms/form-reactive.ts | 20 |
2 files changed, 22 insertions, 4 deletions
diff --git a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts index 5cab9e9df..545e37857 100644 --- a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts +++ b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts | |||
@@ -292,6 +292,9 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { | |||
292 | } | 292 | } |
293 | 293 | ||
294 | formValidated () { | 294 | formValidated () { |
295 | this.forceCheck() | ||
296 | if (!this.form.valid) return | ||
297 | |||
295 | const value: ComponentCustomConfig = this.form.getRawValue() | 298 | const value: ComponentCustomConfig = this.form.getRawValue() |
296 | 299 | ||
297 | forkJoin([ | 300 | forkJoin([ |
@@ -381,8 +384,7 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { | |||
381 | this.customConfig = { ...config, instanceCustomHomepage: homepage } | 384 | this.customConfig = { ...config, instanceCustomHomepage: homepage } |
382 | 385 | ||
383 | this.updateForm() | 386 | this.updateForm() |
384 | // Force form validation | 387 | this.markAllAsDirty() |
385 | this.forceCheck() | ||
386 | }, | 388 | }, |
387 | 389 | ||
388 | error: err => this.notifier.error(err.message) | 390 | error: err => this.notifier.error(err.message) |
diff --git a/client/src/app/shared/shared-forms/form-reactive.ts b/client/src/app/shared/shared-forms/form-reactive.ts index 6b3a6c773..a19ffdd82 100644 --- a/client/src/app/shared/shared-forms/form-reactive.ts +++ b/client/src/app/shared/shared-forms/form-reactive.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | 1 | ||
2 | import { FormGroup } from '@angular/forms' | 2 | import { AbstractControl, FormGroup } from '@angular/forms' |
3 | import { wait } from '@root-helpers/utils' | 3 | import { wait } from '@root-helpers/utils' |
4 | import { BuildFormArgument, BuildFormDefaultValues } from '../form-validators/form-validator.model' | 4 | import { BuildFormArgument, BuildFormDefaultValues } from '../form-validators/form-validator.model' |
5 | import { FormValidatorService } from './form-validator.service' | 5 | import { FormValidatorService } from './form-validator.service' |
@@ -44,6 +44,21 @@ export abstract class FormReactive { | |||
44 | } while (this.form.status === 'PENDING') | 44 | } while (this.form.status === 'PENDING') |
45 | } | 45 | } |
46 | 46 | ||
47 | protected markAllAsDirty (controlsArg?: { [ key: string ]: AbstractControl }) { | ||
48 | const controls = controlsArg || this.form.controls | ||
49 | |||
50 | for (const key of Object.keys(controls)) { | ||
51 | const control = controls[key] | ||
52 | |||
53 | if (control instanceof FormGroup) { | ||
54 | this.markAllAsDirty(control.controls) | ||
55 | continue | ||
56 | } | ||
57 | |||
58 | control.markAsDirty() | ||
59 | } | ||
60 | } | ||
61 | |||
47 | protected forceCheck () { | 62 | protected forceCheck () { |
48 | this.onStatusChanged(this.form, this.formErrors, this.validationMessages, false) | 63 | this.onStatusChanged(this.form, this.formErrors, this.validationMessages, false) |
49 | } | 64 | } |
@@ -59,7 +74,8 @@ export abstract class FormReactive { | |||
59 | this.onStatusChanged( | 74 | this.onStatusChanged( |
60 | form.controls[field] as FormGroup, | 75 | form.controls[field] as FormGroup, |
61 | formErrors[field] as FormReactiveErrors, | 76 | formErrors[field] as FormReactiveErrors, |
62 | validationMessages[field] as FormReactiveValidationMessages | 77 | validationMessages[field] as FormReactiveValidationMessages, |
78 | onlyDirty | ||
63 | ) | 79 | ) |
64 | continue | 80 | continue |
65 | } | 81 | } |