I need to write a custom validation,
- If nationality is 1 then passport is mandatory - this had done.
- If nationality is 2 then either civilId or passport number is mandatory - needed solution for this
Point 2 how can i achieve.
So that error message should display in html like this
<span *ngIf="form.get('passportNo').errors" class="tooltiptext">{{' passportNo is required'}}</span>
this.form = this.fb.group({
civilId: [""],
nationality: [""]
passportNo: [""],
})
setExpatValidators() {
const passportNo = this.form.get('passportNo');
this.form.get('nationality').valueChanges
.subscribe(nationality => {
if(nationality == 1){
passportNo.setValidators([Validators.required]);
}
});
}
submitForm(){
if (!this.form.valid) {
return;
}
Suggest if there any other way