Project

General

Profile

1
/**
2
 * Created by stefania on 5/2/17.
3
 */
4
import {Component, OnInit, Input} from '@angular/core';
5
import {FormGroup, FormBuilder, Validators} from "@angular/forms";
6
import {Topic} from "../../domain/topic";
7

    
8

    
9
@Component({
10
    selector: 'questions-form',
11
    templateUrl: './questions-form.component.html',
12
})
13

    
14
export class QuestionsFormComponent implements OnInit{
15

    
16
    @Input('group')
17
    myForm: FormGroup;
18

    
19
    @Input() availableTopics : Topic[] = [];
20

    
21
    constructor(private _fb: FormBuilder){}
22

    
23
    ngOnInit(): void {
24
    }
25

    
26
    public get form() {
27
        return this._fb.group({
28
            question : ['', Validators.required],
29
            answer : ['', Validators.required],
30
            topics : [[],Validators.required],
31
            weight : ['0.0', Validators.required],
32
            isActive : true,
33
            _id : '',
34
            // date : ''
35
        });
36
    }
37

    
38
    public reset() {
39
        this.myForm.patchValue({
40
            question : '',
41
            answer : '',
42
            topics : [],
43
            weight : '0.0',
44
            // date : '',
45
            isActive : true,
46
            _id : ''
47
        });
48
        this.myForm.markAsPristine();
49
    }
50

    
51
}
(2-2/8)