I'm currently working on setting up user form validation, where the user must input either their mobile number or email address.
Below is the HTML code for adding a guest reaction form:
<form class="new_guest" id="new_guest" [formGroup]="addGuestForm" (ngSubmit)="onSubmit()">
<div class="form-group">
<input placeholder="Enter guest name" class="add-guests form-control ui-autocomplete-input" type="text" formControlName="name"
id="guest_name" autocomplete="off">
</div>
<div class="form-group">
<input placeholder="Enter guest email" class="add-guests form-control ui-autocomplete-input" type="text" formControlName="email"
id="guest_email" autocomplete="off">
</div>
<div class="form-group">
<input placeholder="Mobile Number, If any" class="add-guests form-control ui-autocomplete-input" type="text" formControlName="mobile"
id="guest_mobile" autocomplete="off">
</div>
<input type="submit" class="btn btn-default btn-block" id="add_guest" value="ADD GUEST" [disabled]="!addGuestForm.valid">
</form
This is how the structure of AddGuest init looks like:
this.addGuestForm = new FormGroup({
'name': new FormControl(null, Validators.required),
'email': new FormControl(null, Validators.email),
'mobile': new FormControl(null)
})
If you have any suggestions or solutions, please feel free to share. Thank you!