I have a form called verification form and a form array named RepDetails with three fields. Initially, the form displays three fields, but users can add more details by clicking on "add more". I need assistance in ensuring that Mydetails[0].name is not identical to mydetails[1].name. Can anyone provide guidance on this issue?
Myform = this.fb.group({
Mydetails: this.fb.array([this.createMydetails()])
});
createMydetails(): FormGroup {
return this.fb.group({
Myname: ['', Validators.required ],
Myid: ['', Validators.required],
Myphone: ['', Validators.required]
});
}
Html
<div
formArrayName="Mydetails"
*ngFor="let item of Mydetails.controls; let i = index"
>
<div [formGroupName]="i">
<mat-form-field appearance="outline">
<mat-label class="required">
Name
</mat-label>
<input
appAlphaNumeric
[maxlength]="maxRepNamelen"
formControlName="Myname"
class="mat-body-1"
matInput
/>
</mat-form-field>
<mat-form-field appearance="outline">
<mat-label class="required">
Id
</mat-label>
<input
appAlphaNumeric
formControlName="Myid"
class="mat-body-1"
matInput
/>
</mat-form-field>
<div class="phn-wrapper">
<ngx-intl-tel-input
[cssClass]="'int-phn'"
[searchCountryField]="[
SearchCountryField.Iso2,
SearchCountryField.Name
]"name="phone"
formControlName="Myphone"
>
</ngx-intl-tel-input>
</div>
<mat-icon
*ngIf="Mydetails.length > 1"
(click)="remove(i)"
class="close"
>close</mat-icon
>
</div>
</div>
class="add-fields"
(click)="add()"
>
<mat-icon class="icon">add_circle_outline</mat-icon>
<span class="text mat-button">
{{"ADD MORE"}}</span
>
</div>