I am trying to create a simple angular 2 reactive forms with email and phone number. Below is my code . I am facing two problems here.
Initially verify button should be disable. It should be enabled , only when email field is entered.
Second issue is I want to have only one field enabled at time. If user starts typing in email, then phone number should be disabled and vice versa. Save button will be enabled either if email OR phone no is entered
How do I achieve this?
<form [formGroup]="personalDtlsForm">
<div class="form-group" [ngClass]="displayFieldCss('inputValue')">
<div class="row">
<div class="col">
<label for="inputValue" class="control-label required">Email</label>
</div>
</div>
<div class="row">
<div class="col-9">
<input type="text" id="email" class="form-control" formControlName="inputValue">
</div>
<div class="col-3">
<button type="button" id="verifyBtn" class="btn btn-primary btn-large" (click)="verify()">Verify</button>
</div>
</div>
</div>
<div class="form-group row" [ngClass]="displayFieldCss('phoneNo')">
<div class="col paddingTop">
<label for="phoneNo" class="userID control-label textColor">Phone
</label>
<input type="number" class="form-control" id="phoneNo" formControlName="phoneNo">
</div>
</div>
<div class="viewdetailbtn">
<button type="button" [disabled]="!personalDtlsForm.valid" class="btn btn-primary btn-large btnwidth marginBottom" (click)="savePersonalDtls()">Save</button>
</div>
</form>
this.personalDtlsForm = this.formBuilder.group({
inputValue: [null, [Validators.required, Validators.email]],
phoneNo: [null, Validators.required]
});