45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
// vim: set tw=80 ts=2 sw=2 sts=2 :
|
|
import { Component, OnInit, OnChanges, Input, Output, EventEmitter } from '@angular/core';
|
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
|
|
|
import { Account } from './account';
|
|
|
|
@Component({
|
|
selector: 'account-form',
|
|
exportAs: 'accountForm',
|
|
templateUrl: './accountForm.component.html'
|
|
})
|
|
export class AccountFormComponent implements OnInit {
|
|
public form: FormGroup;
|
|
@Input() account: Account;
|
|
@Output('submit') submitEventEmitter: EventEmitter<void> = new EventEmitter<void>();
|
|
|
|
constructor(private formBuilder: FormBuilder) {}
|
|
|
|
ngOnInit() {
|
|
this.form = this.formBuilder.group({
|
|
name: ['', Validators.required],
|
|
authorizedOverdraft: ['', [Validators.required, Validators.max(0)]],
|
|
});
|
|
|
|
this.form.patchValue({
|
|
name: this.account.name,
|
|
authorizedOverdraft: this.account.authorized_overdraft
|
|
});
|
|
}
|
|
|
|
submit() {
|
|
if(this.form.valid) {
|
|
this.submitEventEmitter.emit();
|
|
}
|
|
}
|
|
|
|
get name() {
|
|
return this.form.get('name');
|
|
}
|
|
|
|
get authorizedOverdraft() {
|
|
return this.form.get('authorizedOverdraft');
|
|
}
|
|
}
|