Skip to content

Instantly share code, notes, and snippets.

@JIntrocaso
Created September 25, 2020 21:26
Show Gist options
  • Save JIntrocaso/857ac5cbda1f34d0ca1afdd948f2a455 to your computer and use it in GitHub Desktop.
Save JIntrocaso/857ac5cbda1f34d0ca1afdd948f2a455 to your computer and use it in GitHub Desktop.
Form Field Component
<div [formGroup]='formGroup'>
<label [attr.for]='field.key'>{{field.title}}:</label>
<div [ngSwitch]="field.type" class='field-group'>
<div *ngSwitchCase="'text'">
<input type='text' [formControlName]="field.key" [id]='field.key' />
</div>
<div class='error-message' *ngIf='!isValid' role="alert">{{field.title}} is required</div>
</div>
</div>
export class FormFieldInputComponent implements OnInit {
@Input() field: ContactFormField
@Input() formGroup: FormGroup;
constructor() { }
ngOnInit(): void {
}
get isValid() {
return this.formGroup.controls[this.field.key].valid || this.formGroup.controls[this.field.key].untouched;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment