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 () {
this.forceCheck()
if (!this.form.valid) return
const value: ComponentCustomConfig = this.form.getRawValue()
forkJoin([
@ -381,8 +384,7 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
this.customConfig = { ...config, instanceCustomHomepage: homepage }
this.updateForm()
// Force form validation
this.forceCheck()
this.markAllAsDirty()
},
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 { BuildFormArgument, BuildFormDefaultValues } from '../form-validators/form-validator.model'
import { FormValidatorService } from './form-validator.service'
@ -44,6 +44,21 @@ export abstract class FormReactive {
} 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 () {
this.onStatusChanged(this.form, this.formErrors, this.validationMessages, false)
}
@ -59,7 +74,8 @@ export abstract class FormReactive {
this.onStatusChanged(
form.controls[field] as FormGroup,
formErrors[field] as FormReactiveErrors,
validationMessages[field] as FormReactiveValidationMessages
validationMessages[field] as FormReactiveValidationMessages,
onlyDirty
)
continue
}