X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fshared-forms%2Fform-reactive.ts;h=30b59c141d29f867a6d1f417f61f58993116b488;hb=3c065fe3b3e1385d59ad1980251d14b712648155;hp=f2ce8236006eff90c34b614ddae751a6a657e333;hpb=61cc1c03bf6f12af7c1b2e2a7d2fdaa563c37b59;p=github%2FChocobozzz%2FPeerTube.git 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 { if (control.dirty) this.formChanged = true - // Don't care if dirty on force check - const isDirty = control.dirty || forceCheck === true - if (control && isDirty && control.enabled && !control.valid) { - const messages = validationMessages[field] - for (const key of Object.keys(control.errors)) { - formErrors[field] += messages[key] + ' ' - } + if (forceCheck) control.updateValueAndValidity({ emitEvent: false }) + if (!control || !control.dirty || !control.enabled || control.valid) continue + + const staticMessages = validationMessages[field] + for (const key of Object.keys(control.errors)) { + const formErrorValue = control.errors[key] + + // Try to find error message in static validation messages first + // Then check if the validator returns a string that is the error + if (typeof formErrorValue === 'boolean') formErrors[field] += staticMessages[key] + ' ' + else if (typeof formErrorValue === 'string') formErrors[field] += control.errors[key] + else throw new Error('Form error value of ' + field + ' is invalid') } } }