-
-
Save JIntrocaso/857ac5cbda1f34d0ca1afdd948f2a455 to your computer and use it in GitHub Desktop.
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