Permalink
Switch branches/tags
greenkeeper/@angular/cli-1.5.2 greenkeeper/@angular/cli-1.5.3 greenkeeper/@angular/cli-1.5.4 greenkeeper/@angular/cli-1.5.5 greenkeeper/@angular/cli-1.6.0 greenkeeper/@angular/cli-1.6.1 greenkeeper/@angular/cli-1.6.2 greenkeeper/@angular/cli-1.6.3 greenkeeper/@angular/cli-1.6.4 greenkeeper/@angular/cli-1.6.5 greenkeeper/@angular/cli-1.6.6 greenkeeper/@angular/cli-1.6.7 greenkeeper/@angular/cli-1.6.8 greenkeeper/@angular/cli-1.7.0 greenkeeper/@angular/cli-1.7.1 greenkeeper/@angular/cli-1.7.2 greenkeeper/@angular/cli-1.7.3 greenkeeper/@angular/cli-1.7.4 greenkeeper/@angular/cli-6.0.0-beta.5 greenkeeper/@angular/cli-6.0.0-rc.3 greenkeeper/@angular/cli-6.0.0-rc.4 greenkeeper/@angular/cli-6.0.2 greenkeeper/@angular/cli-6.0.3 greenkeeper/@angular/cli-6.0.4 greenkeeper/@angular/cli-6.0.5 greenkeeper/@angular/cli-7.0.7 greenkeeper/@angular/cli-7.1.0 greenkeeper/@angular/cli-7.1.1 greenkeeper/@angular/cli-7.1.2 greenkeeper/@angular/cli-7.1.3 greenkeeper/@angular/language-service-5.2.2 greenkeeper/@angular/language-service-5.2.3 greenkeeper/@angular/language-service-5.2.5 greenkeeper/@angular/language-service-5.2.6 greenkeeper/@angular/language-service-5.2.7 greenkeeper/@angular/language-service-5.2.8 greenkeeper/@angular/language-service-5.2.9 greenkeeper/@angular/language-service-5.2.10 greenkeeper/@angular/language-service-6.0.0 greenkeeper/@angular/language-service-6.0.1 greenkeeper/@angular/language-service-6.0.2 greenkeeper/@angular/language-service-6.0.3 greenkeeper/@angular/language-service-pin-5.2.1 greenkeeper/@angular/router-5.2.2 greenkeeper/@angular/router-5.2.3 greenkeeper/@angular/router-5.2.4 greenkeeper/@angular/router-5.2.5 greenkeeper/@angular/router-5.2.6 greenkeeper/@angular/router-5.2.7 greenkeeper/@angular/router-5.2.8 greenkeeper/@angular/router-5.2.9 greenkeeper/@angular/router-5.2.10 greenkeeper/@angular/router-6.0.0 greenkeeper/@angular/router-6.0.1 greenkeeper/@angular/router-6.0.2 greenkeeper/@angular/router-6.0.3 greenkeeper/@angular/router-pin-5.2.1 greenkeeper/bootstrap-4.0.0 greenkeeper/bootstrap-4.1.0 greenkeeper/bootstrap-4.1.1 greenkeeper/bootstrap-4.1.2 greenkeeper/bootstrap-4.1.3 greenkeeper/core-js-2.5.4 greenkeeper/core-js-2.5.5 greenkeeper/core-js-2.5.6 greenkeeper/core-js-2.5.7 greenkeeper/core-js-2.6.0 greenkeeper/core-js-pin-2.5.3 master
Nothing to show
Find file Copy path
68e421f Aug 3, 2017
1 contributor

Users who have contributed to this file

56 lines (48 sloc) 1.38 KB
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
@Component({
selector: 'app-submit-flag-form',
templateUrl: './submit-flag-form.component.html',
styles: []
})
export class SubmitFlagFormComponent implements OnInit {
form: FormGroup;
private formSumitAttempt: boolean;
constructor(private formBuilder: FormBuilder) {}
ngOnInit() {
this.form = this.formBuilder.group({
name: [null, Validators.required],
email: [null, [Validators.required, Validators.email]],
address: this.formBuilder.group({
street: [null, Validators.required],
street2: [null],
zipCode: [null, Validators.required],
city: [null, Validators.required],
state: [null, Validators.required],
country: [null, Validators.required]
})
});
}
isFieldValid(field: string) {
return (
(!this.form.get(field).valid && this.form.get(field).touched) ||
(this.form.get(field).untouched && this.formSumitAttempt)
);
}
displayFieldCss(field: string) {
return {
'has-error': this.isFieldValid(field),
'has-feedback': this.isFieldValid(field)
};
}
onSubmit() {
this.formSumitAttempt = true;
if (this.form.valid) {
console.log('form submitted');
}
}
reset() {
this.form.reset();
this.formSumitAttempt = false;
}
}