Check admin config when loading the page

Avoid issues when an invalid config was set in the configuration file
pull/5250/head
Chocobozzz 2022-09-07 16:24:44 +02:00
parent 08d2761097
commit 8b69f9f028
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 22 additions and 4 deletions

View File

@ -292,6 +292,9 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
} }
formValidated () { formValidated () {
this.forceCheck()
if (!this.form.valid) return
const value: ComponentCustomConfig = this.form.getRawValue() const value: ComponentCustomConfig = this.form.getRawValue()
forkJoin([ forkJoin([
@ -381,8 +384,7 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
this.customConfig = { ...config, instanceCustomHomepage: homepage } this.customConfig = { ...config, instanceCustomHomepage: homepage }
this.updateForm() this.updateForm()
// Force form validation this.markAllAsDirty()
this.forceCheck()
}, },
error: err => this.notifier.error(err.message) error: err => this.notifier.error(err.message)

View File

@ -1,5 +1,5 @@
import { FormGroup } from '@angular/forms' import { AbstractControl, FormGroup } from '@angular/forms'
import { wait } from '@root-helpers/utils' import { wait } from '@root-helpers/utils'
import { BuildFormArgument, BuildFormDefaultValues } from '../form-validators/form-validator.model' import { BuildFormArgument, BuildFormDefaultValues } from '../form-validators/form-validator.model'
import { FormValidatorService } from './form-validator.service' import { FormValidatorService } from './form-validator.service'
@ -44,6 +44,21 @@ export abstract class FormReactive {
} while (this.form.status === 'PENDING') } while (this.form.status === 'PENDING')
} }
protected markAllAsDirty (controlsArg?: { [ key: string ]: AbstractControl }) {
const controls = controlsArg || this.form.controls
for (const key of Object.keys(controls)) {
const control = controls[key]
if (control instanceof FormGroup) {
this.markAllAsDirty(control.controls)
continue
}
control.markAsDirty()
}
}
protected forceCheck () { protected forceCheck () {
this.onStatusChanged(this.form, this.formErrors, this.validationMessages, false) this.onStatusChanged(this.form, this.formErrors, this.validationMessages, false)
} }
@ -59,7 +74,8 @@ export abstract class FormReactive {
this.onStatusChanged( this.onStatusChanged(
form.controls[field] as FormGroup, form.controls[field] as FormGroup,
formErrors[field] as FormReactiveErrors, formErrors[field] as FormReactiveErrors,
validationMessages[field] as FormReactiveValidationMessages validationMessages[field] as FormReactiveValidationMessages,
onlyDirty
) )
continue continue
} }