Project

General

Profile

1
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
            name : ['', Validators.required]
25
        });
26
    }
27

    
28
    public reset() {
29
        this.myForm.patchValue({
30
            name : '',
31
            _id : ''
32
        });
33
    }
34

    
35
    handleError(message: string, error) {
36
        if(error == null) {
37
            this.reset();
38
        }
39
        this.errorMessage = message + ' (Server responded: ' + error + ')';
40
    }
41
}
(6-6/6)