]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/forms/form-reactive.ts
Client: add basic support to report video abuses
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / forms / form-reactive.ts
CommitLineData
4b2f33f3
C
1import { FormGroup } from '@angular/forms';
2
3export abstract class FormReactive {
4 abstract form: FormGroup;
5 abstract formErrors: Object;
6 abstract validationMessages: Object;
7
8 abstract buildForm(): void;
9
10 protected onValueChanged(data?: any) {
11 for (const field in this.formErrors) {
12 // clear previous error message (if any)
13 this.formErrors[field] = '';
14 const control = this.form.get(field);
15
16 if (control && control.dirty && !control.valid) {
17 const messages = this.validationMessages[field];
18 for (const key in control.errors) {
19 this.formErrors[field] += messages[key] + ' ';
20 }
21 }
22 }
23 }
bf57d5ee
C
24
25 // Same as onValueChanged but force checking even if the field is not dirty
26 protected forceCheck() {
27 for (const field in this.formErrors) {
28 // clear previous error message (if any)
29 this.formErrors[field] = '';
30 const control = this.form.get(field);
31
32 if (control && !control.valid) {
33 const messages = this.validationMessages[field];
34 for (const key in control.errors) {
35 this.formErrors[field] += messages[key] + ' ';
36 }
37 }
38 }
39 }
4b2f33f3 40}