// 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 { Logger } from '@nsalaun/ng-logger'; import { Account } from './account'; @Component({ selector: 'account-form', exportAs: 'accountForm', template: `

The account name is required.

.00€

The authorized overdraft is required.

The authorized overdraft must be less than or equal to 0.

` }) export class AccountFormComponent implements OnInit { public form: FormGroup; @Input() account: Account; @Output('submit') submitEventEmitter: EventEmitter = new EventEmitter(); 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'); } }