I have form like below :
this.configGroup = new FormGroup({
accountOne: new FormControl(null),
accountTwo: new FormControl(null),
prefix: new FormControl(""),
suffix: new FormControl(""),
critical: new FormControl(null),
medium: new FormControl(null),
low: new FormControl(null),
none: new FormControl(null)
});
HTML code :
<div class="cred-ref-id-wrap">
<label for="prefix"
[invalid]="(!configGroup?.controls?.prefix?.pristine) && (!configGroup?.controls?.prefix?.valid)">
prefix
<input
[formControlName]="'prefix'"
[placeholder]="'release"
[autocomplete]="'off'"
(focusout)="getValue('prefix')">
</label>
</div>
here I have a situation like user needs to select at least one form control in between suffix or prefix and rest all doesn’t matter but user needs to select compulsory one in between suffix or prefix.
How can be implemented in angular.
2
Answers
You can create a custom Validator and apply it to your form or each control using the
setValidators
method.Here is a quick example :
validator is your solution
Then added to your form group