Project

General

Profile

1
import {Component, OnInit, Input} from '@angular/core';
2
import {FormGroup, FormBuilder, Validators} from "@angular/forms";
3

    
4
@Component({
5
    selector: 'community-form',
6
    templateUrl: './community-form.component.html',
7
})
8

    
9
export class CommunityFormComponent implements OnInit{
10

    
11
    @Input('group')
12
    myForm: FormGroup;
13

    
14
    public errorMessage: string;
15

    
16
    constructor(public _fb: FormBuilder) {}
17

    
18
    ngOnInit(): void {}
19

    
20
    public get form() {
21
      return this._fb.group({
22
        _id: '',
23
        pid: ['', Validators.required],
24
        name: ['', Validators.required],
25
        type: ['', Validators.required]
26
      });
27
    }
28

    
29
    public reset() {
30
      this.myForm.patchValue({
31
        name : '',
32
        _id : '',
33
        pid: '',
34
        type: ''
35
      });
36
    }
37

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