]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/forms/form-reactive.ts
Use typescript standard and lint all files
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / forms / form-reactive.ts
index 1e8a69771c5ffe37d563a665cb8fa026e6c38185..e7764d0695d1fe197e500f298c54159d7d6c7343 100644 (file)
@@ -1,22 +1,38 @@
-import { FormGroup } from '@angular/forms';
+import { FormGroup } from '@angular/forms'
 
 export abstract class FormReactive {
-  abstract form: FormGroup;
-  abstract formErrors: Object;
-  abstract validationMessages: Object;
+  abstract form: FormGroup
+  abstract formErrors: Object
+  abstract validationMessages: Object
 
-  abstract buildForm(): void;
+  abstract buildForm (): void
 
-  protected onValueChanged(data?: any) {
+  protected onValueChanged (data?: any) {
     for (const field in this.formErrors) {
       // clear previous error message (if any)
-      this.formErrors[field] = '';
-      const control = this.form.get(field);
+      this.formErrors[field] = ''
+      const control = this.form.get(field)
 
       if (control && control.dirty && !control.valid) {
-        const messages = this.validationMessages[field];
+        const messages = this.validationMessages[field]
         for (const key in control.errors) {
-          this.formErrors[field] += messages[key] + ' ';
+          this.formErrors[field] += messages[key] + ' '
+        }
+      }
+    }
+  }
+
+  // Same as onValueChanged but force checking even if the field is not dirty
+  protected forceCheck () {
+    for (const field in this.formErrors) {
+      // clear previous error message (if any)
+      this.formErrors[field] = ''
+      const control = this.form.get(field)
+
+      if (control && !control.valid) {
+        const messages = this.validationMessages[field]
+        for (const key in control.errors) {
+          this.formErrors[field] += messages[key] + ' '
         }
       }
     }