/form-field-input.component.html Secret
Created
September 25, 2020 21:26
Star
You must be signed in to star a gist
Form Field Component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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