Project

General

Profile

1 50183 konstantin
import {Component, OnInit, Input} from '@angular/core';
2
import {FormGroup, FormArray, FormBuilder, Validators} from "@angular/forms";
3
import { HelpContentService } from "../../services/help-content.service";
4
5
@Component({
6
    selector: 'community-form',
7
    templateUrl: './community-form.component.html',
8
})
9
10
export class CommunityFormComponent implements OnInit{
11
12
    @Input('group')
13
    myForm: FormGroup;
14
15
    public errorMessage: string;
16
17
    constructor(public _fb: FormBuilder, private _helpContentService: HelpContentService){}
18
19
    ngOnInit(): void {}
20
21
    public get form() {
22
        return this._fb.group({
23
            _id : '',
24 50388 konstantin
            pid: ['', Validators.required],
25 50183 konstantin
            name : ['', Validators.required]
26
        });
27
    }
28
29
    public reset() {
30
        this.myForm.patchValue({
31
            name : '',
32 50388 konstantin
            _id : '',
33
            pid: ''
34 50183 konstantin
        });
35
    }
36
37
    handleError(message: string, error) {
38
        if(error == null) {
39
            this.reset();
40
        }
41
        this.errorMessage = message + ' (Server responded: ' + error + ')';
42
    }
43
}