connect-admin/app/pages/divId/divId-form.component.ts

54 lines
1.3 KiB
TypeScript

import {Component, OnInit, Input} from '@angular/core';
import {FormGroup, FormArray, FormBuilder, Validators} from "@angular/forms";
import { HelpContentService } from "../../services/help-content.service";
import { Page } from "../../domain/page";
@Component({
selector: 'divId-form',
templateUrl: './divId-form.component.html',
})
export class DivIdFormComponent implements OnInit{
@Input('group')
myForm: FormGroup;
@Input('communityPid')
communityPid: string;
@Input('pageId')
pageId: string;
@Input('availablePages')
availablePages : Page[] = [];
public errorMessage: string;
constructor(public _fb: FormBuilder, private _helpContentService: HelpContentService){}
ngOnInit(): void {
}
public get form() {
return this._fb.group({
_id : '',
name : ['', Validators.required],
page : [this.pageId,Validators.required],
community : this.communityPid,
});
}
public reset() {
this.myForm.patchValue({
_id : '',
name : '',
page: '',
community: this.communityPid
});
}
handleError(message: string, error) {
if(error == null) {
this.reset();
}
this.errorMessage = message + ' (Server responded: ' + error + ')';
}
}